不允许 Android WCF 方法
我有以下代码,应该通过 WCF 服务将两个字段插入到数据库中,但在 Eclipse 中测试时收到 405 Method Not allowed 错误。
WCF 可在 Fiddler 和我的测试 C# Web 客户端上运行,我仅通过手机从 Android 收到错误,这让我相信问题可能出在这段代码中!
HttpPost request = new HttpPost("http://www.mysite.com/myservice.svc/postname?fname=fred&lname=frognoggle");
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
Log.d("WebInvoke", "Saving : " + response.getStatusLine().getStatusCode());
谁能看到我错过了什么!
编辑
我正在 Fiddler 中发帖,如果我发帖:
http://www.mysite.com/myservice.svc/postname?fname=fred&lname=frognoggle
一切正常。
干杯,
迈克。
I have the following code that should insert two fields into a database via a WCF Service but I get a 405 Method Not Allowed error when I test in Eclipse.
The WCF works from both Fiddler and my testing C# web client, I only get the error from Android via my phone, leading me to believe the problem may be in this code!
HttpPost request = new HttpPost("http://www.mysite.com/myservice.svc/postname?fname=fred&lname=frognoggle");
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
Log.d("WebInvoke", "Saving : " + response.getStatusLine().getStatusCode());
Can anyone see what I’m missing!
Edit
I'm doing a post in Fiddler and if I post:
http://www.mysite.com/myservice.svc/postname?fname=fred&lname=frognoggle
It all works fine works.
Cheers,
Mike.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新:按请求返回。下面的代码是我用来在 Android 上进行 JSON POST 的代码,它对我有用。
您正在 Android 代码中执行 HTTP POST。你也在fiddler中做POST还是在做GET?我问的原因是您没有随帖子发送正文,仅设置查询字符串。我已包含对 WCF 服务执行 JSON POST 操作的 Android 代码。
希望这有帮助...
如果您发布更多信息,我将很乐意提供帮助并更新答案。
Update: back by request. The code below is what I am using to make a JSON POST on Android and it is working for me.
You are doing an HTTP POST in your Android code. Are you doing a POST in fiddler too or are you doing a GET? The reason I ask is that you are not sending a body with your post, only setting the query string. I have included my Android code that does a JSON POST to a WCF service.
Hope this helps...
If you post more information I will be glad to help and update answer.
url 看起来像 HttpGet
如果你想使用 HttpPost 你应该把你的参数放在 HttpEntity 中,并且你的参数必须是相应的内容类型,比如 json
the url is looks like a HttpGet
if you want to use HttpPost you should put you param in HttpEntity and you param must be corresponding Content-type like json