我有一個後端爲我的android應用程序,它在POST上返回GET和json上的404。現在,我嘗試使用this snippet做POST請求:但是Android發送GET而不是POST
public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.yoursite.com/api/login");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("email", "[email protected]"));
nameValuePairs.add(new BasicNameValuePair("password", "qwerty"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
服務器接收GET請求。使用curl POST後端按預期返回json。但不知何故httpPost發送GET(!)請求。可能是什麼問題呢?我究竟做錯了什麼?
夥計們,之前標記爲無效問題,努力三次思考:)問題不需要你的*專家意見*,它現在有回答 – Roman 2013-04-22 19:14:18
你可能想檢查你的態度;畢竟,你來到這裏尋求幫助。你沒有答案,你有一個黑客。 – 323go 2013-04-23 13:44:15