2
我想從我的android應用程序發送用戶的電子郵件地址和密碼到數據庫通過POST登錄。通過POST發送登錄細節來自android123
在服務器端,我得到我的數據是這樣的:
$email = $_POST['email'];
$password = clean($_POST['password'];
而且在Android方面我把它像這樣:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("some real URL");
httppost.setHeader("Content-type", "application/json");
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair("email", email));
params.add(new BasicNameValuePair("password", password));
httppost.setEntity(new UrlEncodedFormEntity(params));
// Execute the request
HttpResponse response;
try {
response = httpclient.execute(httppost);
......
即使當我在合法的登錄信息輸入,它失敗了,並說沒有電子郵件地址或密碼。我是否正確地發送信息?
我也試過在下面發送數據,但沒有工作。有什麼建議麼?
JSONObject obj = new JSONObject();
obj.put("email", email);
obj.put("password", password);
httppost.setEntity(new StringEntity(obj.toString()));
可能重複不發送數據](http://stackoverflow.com/questions/10248297/android-http-post-not-sending-data) – cxzp
在其他線程找到答案,問題的內容是相同的答案是頭是錯的 – cxzp