如何LoginActivity从拦截器(非活动类)开始?我已经尝试过Interceptor下面的代码()但不适合我.
拦截器
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request newRequest = chain.request().newBuilder()
.addHeader("Authorization", "Bearer " + auth_token_string)
.build();
Response response = chain.proceed(newRequest);
Log.d("MyApp", "Code : "+response.code());
if (response.code() == 401){
Intent intent = new Intent(SplashActivity.getContextOfApplication(), LoginActivity.class);
startActivity(intent);
finish(); //Not working
return response;
}
return chain.proceed(newRequest);
}
}).build();
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的当前解决方案,有没有比这更好的解决方案?该解决方案必须在每次api呼叫时保持重复.
主要活动
call.enqueue(new Callback<Token>() {
@Override
public void onResponse(Call<Token> call, Response<Token> response) {
if(response.isSuccessful())
{
//success
}
else
{
Intent …Run Code Online (Sandbox Code Playgroud) 我正在使用 RobinHerbots jquery 输入掩码。
如何重新定义“9”,使掩码显示XXXX91 而不是XXXXX1?
编辑:如果可能的话,我想让最后两位数字不可编辑
var autoPopulateNo = 91 //how to show the mask like this XXXX91
$("#number").inputmask({
"mask": "9999" + autoPopulateNo,
clearMaskOnLostFocus: false,
placeholder:"X",
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/jquery.inputmask.bundle.js"></script>
<form action="">
<div>
<label for="number">Mask</label>
<input id="number" type="text"/>
</div>
</form>Run Code Online (Sandbox Code Playgroud)
如何提取名称和网址?
报价_spiders.py
import scrapy
import json
class QuotesSpider(scrapy.Spider):
name = "quotes"
start_urls = ["http://www.lazada.com.my/shop-power-banks2/?price=1572-1572"]
def parse(self, response):
data = json.loads(response.xpath('//script[@type="application/ld+json"]//text()').extract_first())
//how to extract the name and url?
yield data
Run Code Online (Sandbox Code Playgroud)
要提取的数据
<script type="application/ld+json">{"@context":"https://schema.org","@type":"ItemList","itemListElement":[{"@type":"Product","image":"http://my-live-02.slatic.net/p/2/test-product-0601-7378-08684315-8be741b9107b9ace2f2fe68d9c9fd61a-webp-catalog_233.jpg","name":"test product 0601","offers":{"@type":"Offer","availability":"https://schema.org/InStock","price":"99999.00","priceCurrency":"RM"},"url":"http://www.lazada.com.my/test-product-0601-51348680.html?ff=1"}]}</script>
Run Code Online (Sandbox Code Playgroud)