在 android 程序中我使用一个 url 来登录,就像 .www.blah.com/api/login/username/password
.
private void sendAccelerationData()
{
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(7);
nameValuePairs.add(new BasicNameValuePair("","test3"));
nameValuePairs.add(new BasicNameValuePair("","pass3"));
this.sendData(nameValuePairs);
}
private void sendData(ArrayList<NameValuePair> data)
{
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new
HttpPost("http://blah.com/api/login/");
httppost.setEntity(new UrlEncodedFormEntity(data));
HttpResponse response = httpclient.execute(httppost);
}
}
但是获得404错误。如果我把 sendData() 写成:
HttpPost("http://eesnap.com");
sendAccelerationData() 如下:
nameValuePairs.add(new BasicNameValuePair("","api"));
nameValuePairs.add(new BasicNameValuePair("","login"));
nameValuePairs.add(new BasicNameValuePair("","test3"));
nameValuePairs.add(new BasicNameValuePair("","pass3"));
获得200 成功。如果在浏览器上粘贴 www.blah.com/api/login/username/password
最后在浏览器上得到一个结果。