更新: これらの問題は、301 リダイレクトを実行するリバース プロキシが原因でした。URL をリダイレクト先に変更すると、問題が修正されました。
Android から Web サービスへの POST リクエストを行うのに苦労しています。
IIS7 で次の Web サービスを実行しています。
<OperationContract()> _
<Web.WebInvoke(BodyStyle:=WebMessageBodyStyle.Bare, Method:="POST", RequestFormat:=WebMessageFormat.Xml, ResponseFormat:=WebMessageFormat.Xml, UriTemplate:="HelloWorld")> _
Function HelloWorld() As XmlElement
Firefox からこの URL に POST リクエストを送信すると、期待どおりに動作します。
次のコードを使用して Android デバイスからリクエストを行うと:
String sRequest = "http://www.myserviceurl.com/mysevice/HelloWorld";
ArrayList<NameValuePair> arrValues = new ArrayList<NameValuePair>();
arrValues.add(new BasicNameValuePair("hello", "world"));
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpRequest = new HttpPost(sRequest);
httpRequest.setHeader("Content-Type", "application/x-www-form-urlencoded");
httpRequest.setEntity(new UrlEncodedFormEntity(arrValues));
HttpResponse response = httpClient.execute(httpRequest);
Method Not Allowed 405 応答が返され、IIS ログを調べると、この URL への要求が「GET」として表示されます。
リクエストのターゲットを $_SERVER['REQUEST_METHOD'] をエコーする PHP スクリプトに変更すると、出力は POST になります。
Web サービスの web.config には、動詞として GET、HEAD、および POST があります。
私が見落としているものはありますか?