我正在开发一个应用程序,可以连接到我的drupal网站。下面是我尝试使用的代码:
public class SignIn extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
HttpClient client = new DefaultHttpClient();
String postURL = "http://test2.icerge.com/testpoint/user";
HttpPost post = new HttpPost(postURL);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("account[name]", "Bob Kelso"));
params.add(new BasicNameValuePair("account[pass]", "awefulawefulman"));
params.add(new BasicNameValuePair("account[mail]", "bobkelso@sacredheart.org"));
UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params,HTTP.UTF_8);
post.setEntity(ent);
HttpResponse responsePOST = client.execute(post);
HttpEntity resEntity = responsePOST.getEntity();
if (resEntity != null) {
Log.i("RESPONSE",EntityUtils.toString(resEntity));
}
} catch (Exception e) {
e.printStackTrace();
Log.i("ERROR",e.toString());
}
}
}但是,我一直在得到一个java.net.unknownhostexception。我在清单文件中设置了INTERNET权限。
我应该提一下,这个问题不是发生在模拟器上,而是发生在真实的设备上。有没有人可以帮助我,给我一些提示,为什么它会出故障?
发布于 2011-05-12 06:49:44
在Android模拟器上开发时,这是一个常见的问题。停止(终止) adb.exe和模拟器,它通常对我有效。
https://stackoverflow.com/questions/5971442
复制相似问题