我想从我的Android客户端发送一个json字符串到我的.net Rest服务... 任何人都可以帮助我解决这个问题吗?如何将JSON字符串发送到Java的.NET REST服务?
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://myURL");
JSONObject json = new JSONObject();
json.put("name", "i am sample");
StringEntity str = new StringEntity(json.toString());
str.setContentType("application/json; charset=utf-8");
str.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/json; charset=utf-8"));
post.setEntity(str);
HttpResponse response = client.execute(post);
响应是错误的请求。我发送json对象作为字符串?这段代码是否正确?
您是否想要为.net Web服务发布代码(服务属性,它定义了post/get和路由url)?不是整个实现,而是它定义URL路由和获取/发布的地方。 – Aliostad 2010-10-27 10:55:33
@aliostad:这是我的Android客户端code.in myURL我指定了我的URL(http://10.242.48.54/restinsert/Service1.svc/CreateCustomer/Data)。该服务在.net中实现,只接受字符串作为输入。 – Ads 2010-10-27 11:14:07