這是我的第一個項目。當我使用後,我無法發送數據到服務器。android使用HttpPost和StringEntity
這裏是我的代碼:
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":"[email protected]","_password":"aze"}
07-05 13:09:57.733 16809-16809/com.ad_imagine.jsonconnection I/System.out: 0.string: [email protected]
07-05 13:09:57.733 16809-16809/com.ad_imagine.jsonconnection I/System.out: 1.string: [email protected]
07-05 13:09:57.768 16809-16809/com.ad_imagine.jsonconnection I/System.out: 6.Exception: null
什麼是[email protected]
?爲什麼0.string不正確?
你爲什麼要發送JSON數據,但告訴服務器其形式數據? – larsgrefer
你能澄清你想要你的POST請求的樣子嗎? – larsgrefer