我有一个后端为我的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