我搜索了各种SO线程,但没有结果。无论如何,我无法通过改造调用简单的rest api。它是一个补丁api,当我从swagger调用它时,它工作正常,并发送响应。但是当我从android调用它时它不起作用。我有另一个类似的api请求,但它也适用于Android代码。请查看以下详细信息并指导我出错的地方。
Swagger中的API调用
请求网址:http://138.197.110.214:3100/register/resendVerificationCode
参数:
{
"email": "ab@gmail.com",
"requestForNewPassword": true,
"sendMail": true
}
响应
{
"connection": "keep-alive",
"date": "Wed, 07 Feb 2018 21:35:48 GMT",
"transfer-encoding": "chunked",
"cache-control": "no-cache",
"content-encoding": "gzip",
"content-type": "application/json; charset=utf-8",
"vary": "accept-encoding"
}
以下是android调用的详细信息
界面
中的声明@FormUrlEncoded
@PATCH("/register/resendVerificationCode")
public Observable<ResendOTPResponse> doResendForgetOTP(@Field("email") String email, @Field(WebServicesTags.TAG_STR_requestForNewPassword) boolean request, @Field("sendMail") boolean emailbool);
类
中的方法调用Observable<ResendOTPResponse> register = apiservice.doResendForgetOTP(edtUsername.getText().toString(), true, true); register.subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .onErrorResumeNext(throwable -> {
Toast.makeText(mContext, "" + mContext.getResources().getString(R.string.msg_networkerror), Toast.LENGTH_SHORT).show();
return Observable.empty();
})
.subscribe(new Observer<ResendOTPResponse>() {
@Override
public void onCompleted() {
pdi.dismiss();
}
@Override
public void onError(Throwable e) {
((HttpException) e).code();
}
@Override
public void onNext(ResendOTPResponse resendOTPResponse) {
otpRestricter.setCounter(otpRestricter.getCounter() + 1);
showOTPDialog(mContext, 1);
}
});
Logcat输出
D/OkHttp: --> PATCH http://138.197.110.214:3100/register/resendVerificationCode HTTP/1.1
D/OkHttp: Content-Type: application/x-www-form-urlencoded
D/OkHttp: Content-Length: 63
D/OkHttp: email=ahah%40xjxjx.com&requestForNewPassword=true&sendMail=true
D/OkHttp: --> END PATCH (63-byte body)
.
.
.
D/OkHttp: <-- 501 Not Implemented http://138.197.110.214:3100/register/resendVerificationCode (903ms)
D/OkHttp: Content-Type: text/vnd.wap.wml
D/OkHttp: Proxy-Connection: close
D/OkHttp: Connection: close
D/OkHttp: Content-Length: 200
D/OkHttp: OkHttp-Sent-Millis: 1518040494521
D/OkHttp: OkHttp-Received-Millis: 1518040495105
D/OkHttp: <?xml version="1.0"?>
D/OkHttp: <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
D/OkHttp: "http://www.wapforum.org/DTD/wml_1.1.xml">
D/OkHttp: <wml><card id = "error" title = "Error 400">
D/OkHttp: <p>
D/OkHttp: Bad Request
D/OkHttp: </p>
D/OkHttp: </card></wml>
D/OkHttp: <-- END HTTP (200-byte body)