android在提交HTTP请求的时候崩溃
RT,刚开始学习,不知道为什么一执行到client.execute()的时候就崩溃,提示XXX已停止运行,不管参数是post还是get都是这样,新建的工程测试下也是这样。...
RT,刚开始学习,不知道为什么一执行到client.execute()的时候就崩溃,提示XXX已停止运行,不管参数是post还是get都是这样,新建的工程测试下也是这样。
代码如下
private void registerToHost(String username, String password) {
/* HttpPost httpRequest = new HttpPost(uriConnection);
HttpResponse httpResponse = null;
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("user_name", username));
params.add(new BasicNameValuePair("password", password));
try {
httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
httpResponse = new DefaultHttpClient().execute(httpRequest);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} */
DefaultHttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(uriConnection);
try {
HttpResponse response = client.execute(get);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
配置文件已经添加权限 <uses-permission android:name="android.permission.INTERNET" />
uriConnection = "http://***.***.**.***:8080/test/login";
其中***是服务器的ip地址 展开
代码如下
private void registerToHost(String username, String password) {
/* HttpPost httpRequest = new HttpPost(uriConnection);
HttpResponse httpResponse = null;
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("user_name", username));
params.add(new BasicNameValuePair("password", password));
try {
httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
httpResponse = new DefaultHttpClient().execute(httpRequest);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} */
DefaultHttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(uriConnection);
try {
HttpResponse response = client.execute(get);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
配置文件已经添加权限 <uses-permission android:name="android.permission.INTERNET" />
uriConnection = "http://***.***.**.***:8080/test/login";
其中***是服务器的ip地址 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询