String uriPath = "http://192.168.1.82:8088/UserApp.ashx";
InputStream result = null;
HttpPost post = new HttpPost(uriPath);
List<BasicNameValuePair> list = new ArrayList<BasicNameValuePair>();
// 构建表单字段内容
for (Entry<String, Object> entry : params.entrySet()) {
list.add(new BasicNameValuePair(entry.getKey(), entry.getValue() + ""));
}
try {
post.setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8));
//post.addHeader("do", "Login");

HttpClient client = new DefaultHttpClient();
client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, CONSTANT.CONNECTION_TIMEOUT);
client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, CONSTANT.SO_TIMEOUT);

HttpResponse response = client.execute(post);
//response.addHeader("Accept", "application/xml");

if (CONSTANT.CODE_200 == response.getStatusLine().getStatusCode())
result = response.getEntity().getContent();
}
catch (ClientProtocolException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();


if(result.equals(null))
{
Log.v("webserver", "多半没有取到数据");
}
else
Log.v("webserver", "有数据咯");
BufferedReader bf = new BufferedReader(new InputStreamReader(result));
String s = null;
try {
s = bf.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.v("webserver", s);
这个实际的uri地址应该是http://192.168.1.82:8088/UserApp.ashx?do= Login&LoginName=用户名&LoginPwd=密码
我不知道就是?do以及之后的内容怎么封装成一个地址呢?不然以我上面写的代码去请求的话就类似网页直接请求了,是非法法的参数请求,还请给位高手说下。非常感谢

解决方案 »

  1.   

    list里面加进去不就可以了吗?
      

  2.   

    请求的网址是:http://192.168.1.82:8088/UserApp.ashx?do= Login&LoginName=用户名&LoginPwd=密码,想请求这个网址应该用HttpGet请求,不要用HttpPost请求。
      

  3.   

    已经解决啦···谢谢你们两位的回答!最后我还是使用的POST方式来完成的请求!原来是我少写了一句话
    // 构建表单字段内容
    list.add(new BasicNameValuePair("do", args));
    for (Entry<String, Object> entry : params.entrySet()) {
    list.add(new BasicNameValuePair(entry.getKey(), entry.getValue() + ""));
    }在for循环之前我没有加do = 的内容,所以地址不对没有请求道,和服务器端程序员沟通后知道了,我们这里是do =是固定的,至于do=的内容,是变化的,那么请求不同的时候穿进去的参数不同,就用args来表示传入的参数就可以了!