首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android利用HttpURLConnection调用局域网中服务器下的webservice出现有关问题

2012-09-07 
android利用HttpURLConnection调用局域网中服务器上的webservice出现问题问题如下:运行到int code conn.

android利用HttpURLConnection调用局域网中服务器上的webservice出现问题
问题如下:运行到int code = conn.getResponseCode()时;//得到的code是400 出现的错误是filenotfound 请问是什么原因啊


代码:
InputStream in = NumberService.class.getResourceAsStream("projectstatic.xml");  
  byte[] data = StreamUtil.load(in);  
  String content = new String(data);  
   
  // 创建连接对象, 设置请求头, 按照Webservice服务端提供的要求来设置  
  URL url = new URL("http://172.16.230.50/project/projectStatic.asmx");  
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();  
  conn.setConnectTimeout(1000000);  
  conn.setRequestProperty("Host", "172.16.230.50"); 
  //conn.setRequestProperty("Content-type", "application/x-java-serialized-object");
  conn.setRequestProperty("Content-Type", "application/soap+xml; charset=utf-8");  
  conn.setRequestProperty("Content-Length", content.getBytes().length + "");  
  conn.setRequestMethod("POST");  
  conn.setUseCaches(false);
  // 输出数据  
  conn.setDoOutput(true); 
  conn.setDoInput(true);
  //conn.connect();
   
  conn.getOutputStream().write(content.getBytes());  
  conn.getOutputStream().flush();
  conn.getOutputStream().close();

   
// // 获取服务端传回的数据, 解析XML, 得到结果  
  int code = conn.getResponseCode();//得到的code是400 出现的错误是filenotfound 
  if (conn.getResponseCode() == 200) 
  { 
  // 解析返回信息 
  InputStream tmpIn = conn.getInputStream();
  byte[] bs = new byte[tmpIn.available()];
  tmpIn.read(bs);
  tmpIn.close();
  String bsStr = new String(bs, "UTF-8");

  } 


[解决办法]
服务器上没有要连接的文件.

热点排行
Bad Request.