从过去的几个小时开始,我试图将JSONObject发送到PHP服务器。我需要通过参数发送此对象。
有些是这样的:
message={"name":"Firstname","email":"test@test.com"}
这里的消息是我的参数名称。
是的我正在使用HttpClient发布我的请求。正如我所提到的,我需要向服务器发送一个post请求,将JSONObject附加到参数,我使用以下方法:
设置我的确切网址就像http://www.example.com/那么我需要在URL中添加deviceID,日期和消息类型,以使其看起来像http://www.example.com/deviceID/date/140然后到此网址我需要发送帖子请求,它是一个JSONObject,将它附加到名为message的参数。
为此我正在做:
String url = "http ://www.example.com/deviceID/date/140";
JSONObject j = new JSONObject();
j.put("name", "Firstname");
j.put("email", "test@test.com");
HttpClient httpclient = new DefaultHttpClient();
HttpPost request = new HttpPost(url);
BasicHttpParams params = new BasicHttpParams();
params.setParameter("message",j.toString());
request.setParams(params);
HttpResponse response = httpclient.execute(request);
如果我通过这种方式,服务器返回一条JSONObject错误消息,说"error":"name not found"
- 我做错了什么?