将数据从android传递到网站

问题描述:

blahNow我在做一个ANdroid应用程序。在我的应用程序中,我必须使用url登录。就像... www.blah.com/api/login/username/password。将数据从android传递到网站

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 error.and如果我写我的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然后我得到浏览器上的结果

我明白我error.In“GET() '方法我可以像上面这样写代码,但是在post方法中我必须使用名称值对。

尝试:

HttpPost("http://www.blah.com/api/login/"); 
+0

http://eesnap.com/api/login/test3/pass3.Copy此网址的地址栏....你可以检查 – sarath 2012-04-18 06:54:17