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那行错误,新手,不知道哪的问题

解决方案 »

  1.   

    SERVER_URL="http://localhost/androidserver/Ws.asmx?op=GetUserList";
    404是网络错误了,局域网的地址是没法访问到的
      

  2.   

    localhost和127.0.0.1 只适用本机调试。模拟器本身可以看做是另一台机器,所以访问webservice需输入完整的ip地址 
      

  3.   

    final String SERVER_URL="http://localhost/androidserver/Ws.asmx?op=GetUserList";
    你这个地址不能这样写,就像楼上说的它只适用于本机,你可以用完整地址,或者用10.0.0.2都可以的