0
我想从我的Android客户端(Android 4.03) 发送一个json字符串到我的.net休息服务(WCF)。作为回应,我收到了“不良要求”。我有这个服务的.NET测试,它工作正常。错误的请求:从Android客户端发送字符串到.NET REST服务
服务器端代码:
[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)