blahNow我正在做一个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,那么我将在浏览器上获得结果
答案 0 :(得分:1)
尝试:
HttpPost("http://www.blah.com/api/login/");
答案 1 :(得分:0)
我理解我的错误。在'Get()'方法中,我可以像上面那样编写代码但是在post方法中我必须使用名称值对。