android发送请求失败
下面是一个执行访问外网接口返回数据的一个方法
运行虚拟机以后,提示 HttpResponse response = client.execute(request); 报错了
AndroidManifest.xml中增加了下面这句话,还是一样。不知道还需要做什么才不报错?
<uses-permission android:name="android.permission.INTERNET" />
private String getPDAServerData(String url){
HttpClient client = new DefaultHttpClient();
HttpPost request;
String out="";
try {
request = new HttpPost(new URI(url));
HttpResponse response = client.execute(request);
// 判断请求是否成功
if (response.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = response.getEntity();
if (entity != null) {
out = EntityUtils.toString(entity);
//new AlertDialog.Builder(this).setMessage(out).create().show();
}
}
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return out;
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView1 = (TextView)this.findViewById(R.id.msg);
// id,title,thumb,description,inputtime
String str = getPDAServerData(url);
String []arr = str.split("&");//这里是自定义的字符解析,可以忽略
String html = "";
for(int i=0;i<arr.length;i++){
String []arr2 = arr[i].split("|");
html += "<img src=\""+arr[2]+"\" width=\"80\" height=\"80\"/>"+arr2[1];
if(i%2!=0)
html+="<br>";
}
CharSequence charSequence = Html.fromHtml(html);
textView1.setText(charSequence);
}
运行虚拟机以后,提示 HttpResponse response = client.execute(request); 报错了
AndroidManifest.xml中增加了下面这句话,还是一样。不知道还需要做什么才不报错?
<uses-permission android:name="android.permission.INTERNET" />
...全文
相关推荐
安卓开发之简单的通过服务器端验证密码登录
安卓应用程序,通过post请求服务器端Servlet,验证用户名和密码,仅做了密码显示,没有做验证逻辑,小白一枚,希望大家多多指教
安卓Android源码——Android自动发送短信.zip
安卓Android源码——Android自动发送短信.zip
安卓Android源码——自动发送短信.zip
安卓Android源码——自动发送短信.zip
安卓Android源码——精典源码之自动发送短信.zip
安卓Android源码——精典源码之自动发送短信.zip
安卓开发-利用JSON,通过Android客户端访问web服务器,实现一个登录功能.zip.zip
安卓开发-利用JSON,通过Android客户端访问web服务器,实现一个登录功能.zip.zip


