使用Android进行HTTP发布

moh*_*ail 4 android

我需要在我的apllication中通过Post Method将一些值传递给URL.请帮忙

小智 6

这是一些将发出HTTP POST请求的代码.取自http://androidadvice.blogspot.com/2010/10/httppost-request.html,其中还有一些额外的解释.

HttpClient httpclient =  new DefaultHttpClient(httpParameters);
HttpPost httppost = new HttpPost(Constants.MAIN_URL);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("u", eUsername));
nameValuePairs.add(new BasicNameValuePair("p", ePassword));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
Run Code Online (Sandbox Code Playgroud)