【发布时间】:2010-10-27 10:43:38
【问题描述】:
我正在尝试将 json 字符串从我的 android 客户端发送到我的 .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 路由和 get/post 的地方。
-
@alostad:这是我的 android 客户端代码。在 myURL 中,我指定了我的 URL(10.242.48.54/restinsert/Service1.svc/CreateCustomer/Data)。此服务在 .net 中实现,仅接受字符串作为其输入。
标签: .net android web-services