Skip to content

xutils3使用Digest验证的方法 #191

Closed
@rachelhq

Description

需要使用digest验证,xutil2使用起来比较方便,可以使用httpclient;
但是xutils3好像用起来比较麻烦,现在使用的方式如下:

1、首先需要使用异步调用方式:
x.http().post(requestParams, new CustomCallback());

2、CustomCallback 需要继承 InterceptRequestListener,才能在afterRequest(UriRequest request)回调中拿到response中header "WWW-Authenticate"的值

3、需要digest验证的请求,第一次post之后会回调onError(Throwable ex, boolean isOnCallback);
在该回调方法中判断httpcode是否为HTTP_UNAUTHORIZED,是的话自己拼接DigestAuth字符串authString,并且在requestparams中加入新的header:
requestParams.addHeader("Authorization", authString);

4、再一次调用x.http().post(requestParams, new CustomCallback());

这么使用起来有几个限制:必须使用异步方式调用,必须继承InterceptRequestListener,必须在onerror中自己拼接验证heder。。。

请问有没有比较方便的方式?多谢

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions