-
android httpclient 连不上5
目的:用户输入账号和密码后,根据客户端连接服务器,登陆成功为1,不成功为0。
//根据具体的url连接获得数据
public static String queryStringForPost(String url){
HttpPost request = HttpUtil.getHttpPost(url);
String result = null;
try {
HttpResponse response = HttpUtil.getHttpResponse(request);//这行发生了异常
if(response.getStatusLine().getStatusCode()==200){
result = EntityUtils.toString(response.getEntity());
return result;
}
} catch (ClientProtocolException e) {
e.printStackTrace();
result = "网络异常!";
return result;
} catch (IOException e) {
e.printStackTrace();
result = "网络异常!";
return result;
}
return null;
}
//异常的方法
public static HttpResponse getHttpResponse(HttpPost request) throws ClientProtocolException, IOException{
HttpResponse response = new DefaultHttpClient().execute(request);
return response;
}
问题补充:由于传值的原因,所以我将post也定义成get了,参数在url中直接带过来了,所以这就不存在get和post区别
问题补充:sanfeng_chow 写道你先检查一下虚拟机是否可以上网。
检查方法用虚拟机的浏览器打开一个网站。
大哥,的确打不开网站,但是小弟不清楚哪里设置了不能上网哇,希望指点下,以下是我的截图
问题补充:renpeng301 写道Androidmanifest.xml你加这个权限么?
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
大哥我用你的方法果然可以上网了,但是网上很多写的要求设置代理IP和设置DNS这是做什么的啊?
问题补充:renpeng301 写道
Androidmanifest.xml你加这个权限么?
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
大哥我用你的方法果然可以上网了,但是网上很多写的要求设置代理IP和设置DNS这是做什么的啊?
问题补充:renpeng301 写道Androidmanifest.xml你加这个权限么?
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
大哥,我加了这权限后,访问网站是解决了,但是,代码到
HttpResponse response = HttpUtil.getHttpResponse(request);还是发生了IOException,
问题补充:renpeng301 写道
Androidmanifest.xml你加这个权限么?
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
大哥,我加了这权限后,访问网站是解决了,但是,代码到
HttpResponse response = HttpUtil.getHttpResponse(request);还是发生了IOException,
问题补充:这是我的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="huigou.com"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".LoginActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="MainActivity"/>
<activity android:name="huigou.com.RegeditActivity"/>
<activity android:name="huigou.com.ResultActivity"/>
<activity android:name="huigou.com.BehaviorActivity"/>
<activity android:name="huigou.com.MenuActivity"/>
<activity android:name="huigou.com.PromotionActivity"/>
<activity android:name="huigou.com.ShopActivity"/>
<activity android:name="huigou.com.TabMActivity"/>
<activity android:name="huigou.com.TeamActivity"/>
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk android:minSdkVersion="3" />
</manifest>
问题补充:renpeng301 写道你使用 android模拟器 连接 你的本地项目
“http://localhost:8080/Test/"
这么?
是的,我通过get,将数据传递到服务端,然后再服务端做判断得出0或者1,在页面上,具体的url=http://localhost:8080/Test/c/user.do?method=login
但是具体的错误就放生在访问服务器的response响应上,我用IE打开url是可以获得正确值的
但是用HttpResponse response = HttpUtil.getHttpResponse(request);来获得response时候就发生了错误
问题补充:上面url写错了应该是:
url=http://localhost:8080/Test/c/user.do?method=login
&username=123&password=1232011年1月04日 10:51
11个答案 按时间排序 按投票排序
-
Androidmanifest.xml你加这个权限么?
<uses-permission android:name="android.permission.INTERNET" />
</manifest>2011年1月04日 15:46
-
既然都是Get方法的话,但在
private String query(String username,String password){
String queryString = "username="+username+"&password="+password;
String url = HttpUtil.BASE_URL+"m/user.domethod=login&"+queryString;
return HttpUtil.queryStringForPost(url);
}却是queryStringForPost(url)?是否换成queryStringForGet(url)...2011年1月04日 14:54
-
似乎是post和get有点混乱。。。。
建议看看
http://aina-hk55hk.iteye.com/blog/7115442011年1月04日 13:57
相关推荐
Httpclient上传文件,非常有用的jar包 apache-mime4j-0.6.jar httpmime-4.0.jar
Android HttpClient基本使用方法 测试过能用。
struts2 android httpclient 上传文件 客服端 服务器端 亲测通过
这是一个用Httpclient设置代理下载文件的例子
android的Http上载文件 可以实现多文件上载,结合android自身白日提供的强大的HttpClient操作。
利用 android httpclient 编写http协议的例子代码,可以参考添加post,get ,put delete 等功能。工程师文件可以直接编译运行。
android9.0不再支持useLibrary 'org.apache.http.legacy'引入httpclient,需要引入jar
是android的jar中httpclient的源码,是org.apache.http包的源码。其中包含org.apache.http.HttpResponse类。 不是官网上下载的,官网上的源码里面没有org.apache.http.HttpResponse这个类。
该Demo主要介绍使用HttpClient获取网络数据,然后经过JSON后显示出来。另外本文章用到了常用的异步加载技术,AsyncTask类。
android应用开发 httpClient所需jar包 和调用webservice 工具ksoap2 jar 包
Android利用HttpClient实现访问web服务器源码 剥离出HttpClient代码,用来做网页爬虫亦可
android HttpClient 获取网络图片 实例
Android-异步HttpClient框架,采用两种提交方式 Android-异步HttpClient框架(get和post) Android-异步HttpClient框架 csdn博客地址:http://blog.csdn.net/u014657752
Android 使用HttpClient代理
下面给大家展示了AndroidHttpClient结构: public final class AndroidHttpClient extends Object implements HttpClient 前言: 这类其实是Google对阿帕奇的HttpClient的一个封装,一些默认属性有android做了一些...
Android Asynchronous HTTPClient的实现和优化
Android使用HttpClient发送请求、接收响应很简单,只要如下几步即可: Step1:创建HttpClient对象; Step2:如果需要发送GET请求,则创建HttpGet对象; 如果需要发送POST请求,则创建HttpPost对象; Step3:如果...
android HttpClient访问某些Https时,出现了问题,无法访问,好像是要安全验证。此Demo解决了此问题,HttpClient能够Https和Http类型的URL了。 在eclipse下打开工程若有乱码,请把eclipse的字符编码改成UTF-8。
基于Android HttpClient的一个网络连接简单实现,附jar包及源码。
Android使用HttpClient上传文件到服务器完整实例,包括要用到的jar都下libs下面,服务器的源码也有