Androidクライアント(Android 4.03)から.net Restサービス(WCF)にjson文字列を送信しようとしています。そして、応答として「BadRequest」を受け取りました。このサービス用の.NETテスターがあり、正常に動作します。
サーバーサイドコード:
[WebInvoke(UriTemplate = "submit", Method = "POST", RequestFormat = WebMessageFormat.Json)]
public bool SubmitPackage(string instance)
{
log.WriteWarning("Submit");
return true;
}
私のWCF構成
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" maxReceivedMessageSize="327680" helpEnabled="true" automaticFormatSelectionEnabled="false" defaultOutgoingResponseFormat="Json" transferMode="Buffered" />
</webHttpEndpoint>
</standardEndpoints>
Androidクライアントの私のコード
HttpPost request2 = new HttpPost(URL_Submit);
request2.setHeader("content-type", "application/json");
JSONStringer json1 = new JSONStringer().object().key("instance")
.value("hello world").endObject();
StringEntity entity1 = new StringEntity(json1.toString());
entity1.setContentType("application/json;charset=UTF-8");
entity1.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
"application/json;charset=UTF-8"));
request2.setEntity(entity1);
// Send request to WCF service
DefaultHttpClient httpClient = new DefaultHttpClient();
String response1 = httpClient.execute(request2)