关于Android使用HttpPos方式带参数访问Asp.net网页问题

lan120576664 2014-06-18 04:04:27
在浏览器上访问 http://aspspider.info/lanjackg2003/Default.aspx?name=123&psw=456
能够得到结果:
{Name:'123',PassWord:'456'}
但是在android应用中使用如下代码:
 public String posturl(){
String result = "";
InputStream is = null;
try{
HttpPost httppost = new HttpPost("http://aspspider.info/lanjackg2003/Default.aspx");
if(nameValuePairs.isEmpty() == false)
{
BasicNameValuePair NameValuePair1 = new BasicNameValuePair("name","123");
BasicNameValuePair NameValuePair2 = new BasicNameValuePair("psw","456");
List<BasicNameValuePair> list = new ArrayList<BasicNameValuePair>();
list.add(NameValuePair1);
list.add(NameValuePair2);
UrlEncodedFormEntity httpEntity = new UrlEncodedFormEntity(list);
httppost.setEntity(httpEntity);
}

HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
return "Fail to establish http connection!";
}

try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"utf-8"));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();

result=sb.toString();
}catch(Exception e){
return "Fail to convert net stream!";

return result;
}

返回的结果:
{Name:'',PassWord:''}

想问一下,是否android不支持带参访问asp.net的网站?还是我的代码有问题
...全文
345 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
lan120576664 2014-06-18
  • 打赏
  • 举报
回复
自己解决了 http://blog.csdn.net/lan120576664/article/details/32155209

80,469

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧