Ari*_*nua 2 java post android get okhttp
我正在使用需要通过 POST 请求从 web api 获取令牌的 android 应用程序中工作,我使用的是 OkHttp 库版本 2.3.0 但奇怪的是 post 方法正在执行 GET 请求,结果我得到了 405 状态代码,这是方法不允许来自服务器的响应。
这是我的代码。
public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
public String executePOST(){
OkHttpClient client = new OkHttpClient();
.
.
.
.
String url = API_URL + "/oauth/access_token/";
String strResponse = null;
RequestBody body = RequestBody.create(JSON, jsonBody);
Request request = new Request.Builder()
.url(url)
.post(body)
.build();
Response response;
try {
response = client.newCall(request).execute();
strResponse = response.body().string();
} catch (IOException e) {
e.printStackTrace();
}
return strResponse;
}
Run Code Online (Sandbox Code Playgroud)
当我调试代码时,响应对象具有此内容...

知道这有什么问题吗?解决这个问题的可能方法是什么?对你的帮助表示感谢!谢谢...