我试图从我的服务器上使用OkHttp从android应用程序调用put方法。Okhttp Put方法返回'方法不允许'
这是API方法签名:
public void Put(int userId, string regId) { }
这是Android的代码来调用上面的方法...
private boolean SendGCMRegIdToServer(String registrationId, Integer userId) throws IOException {
HttpUrl url = new HttpUrl.Builder()
.scheme("http")
.host(serverApiHost)
.addPathSegment("AppDashboard")
.addPathSegment("api")
.addPathSegment("GCM/")
.build();
MediaType JSON
= MediaType.parse("application/json; charset=utf-8");
String json = "{'userId':" + userId + ","
+ "'regId':'" + registrationId + "'"
+ "}";
RequestBody requestBody = RequestBody.create(JSON, json);
Request request = new Request.Builder()
.url(url)
.put(requestBody)
.build();
//this should post the data to my server
Response response = client.newCall(request).execute();
if(response.code() == 400)
return false;
return true;
}
现在的问题是我得到错误代码405在答复说法不允许,但我不明白问题在哪里,因为我可以用postma成功调用方法n个服务器本身如下的:
http://localhost/AppDashboard/api/GCM?userId=5®Id=123
我想它可能有一些做的整数或字符串正在JSON字符串错误地传递了,但不能为生命明白为什么这不工作...
任何帮助是非常感谢感谢...
你确定你还使用PUT在邮递员? – njzk2