新手问题

rewqaz 2012-06-26 11:34:05
public void onClick(View v) {
final String SERVER_URL="http://localhost/androidserver/Ws.asmx?op=GetUserList";
HttpPost request = new HttpPost(SERVER_URL);
request.addHeader("Content-Type", "application/json; charset=utf-8");
HttpResponse httpResponse = null;
try {
httpResponse = new DefaultHttpClient().execute(request);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

if (httpResponse.getStatusLine().getStatusCode() !=404){
String result = null;
try {
result = EntityUtils.toString(httpResponse.getEntity());
} catch (ParseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

Log.i("result",result);// System.out.println(result);
//JSONArray resultArray=new JSONObject(result).getJSONArray("d");
//TextView tv=(TextView)findViewById();
//tv.setText(((JSONObject)resultArray.get(0)).getString("UserName").toString());

}

这是从网上复制的代码,调用一个webservice 但是提示404那行错误,新手,不知道哪的问题
...全文
107 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
rewqaz 2012-06-26
  • 打赏
  • 举报
回复
换成完整的地址也不行,防火墙也关了,还是不可以
Gongqingshuai 2012-06-26
  • 打赏
  • 举报
回复
localhost和127.0.0.1 只适用本机调试。模拟器本身可以看做是另一台机器,所以访问webservice需输入完整的ip地址
rewqaz 2012-06-26
  • 打赏
  • 举报
回复
ie是能访问到的,模拟器不行吗,怎么解决?
life02 2012-06-26
  • 打赏
  • 举报
回复
SERVER_URL="http://localhost/androidserver/Ws.asmx?op=GetUserList";
404是网络错误了,局域网的地址是没法访问到的
rewqaz 2012-06-26
  • 打赏
  • 举报
回复
继续顶
已经换成192.168.1.102了,不行
lych_0317 2012-06-26
  • 打赏
  • 举报
回复
final String SERVER_URL="http://localhost/androidserver/Ws.asmx?op=GetUserList";


你这个地址不能这样写,就像楼上说的它只适用于本机,你可以用完整地址,或者用10.0.0.2都可以的

80,352

社区成员

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

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