【发布时间】:2016-11-07 09:33:08
【问题描述】:
这是我的第一个项目。当我使用 Post 时,我无法将数据发送到服务器。
这是我的代码:
JSONObject json = new JSONObject();
try
{ json.put("_username", mUsername);
json.put("_password", mPassword);
String s=json.toString();
System.out.println("string: " + s);
StringEntity se = new StringEntity( s,HTTP.UTF_8);
System.out.println("0.string: " + se);
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/x-www-form-urlencoded"));
System.out.println("1.string: " + se);
httpRequest.setEntity(se);
还有catch (Exception e)
这是logcat:
07-05 13:09:57.731 16809-16809/com.ad_imagine.jsonconnection I/System.out: string: {"_username":"lorem@ipsum.fr","_password":"aze"}
07-05 13:09:57.733 16809-16809/com.ad_imagine.jsonconnection I/System.out: 0.string: org.apache.http.entity.StringEntity@3117948
07-05 13:09:57.733 16809-16809/com.ad_imagine.jsonconnection I/System.out: 1.string: org.apache.http.entity.StringEntity@3117948
07-05 13:09:57.768 16809-16809/com.ad_imagine.jsonconnection I/System.out: 6.Exception: null
org.apache.http.entity.StringEntity@3117948 是什么?为什么 0.string 不正确?
【问题讨论】:
-
为什么你发送 JSON 数据却告诉服务器它的表单数据?
-
你能说明你希望你的 POST 请求是什么样子吗?
标签: android android-json androidhttpclient