我正在做一个安卓项目。我是android编程的新手。如何从我的项目向谷歌应用引擎发送 HTTP 发布请求?我搜索并发现此代码用于从 android 发送请求,但它不起作用。以下是我正在使用的代码:
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.example.com/servleturl");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username", userEmailStr));
nameValuePairs.add(new BasicNameValuePair("password", userPasswordStr));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
info.setText(response.toString());
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
提前感谢您的帮助。