android中java.io.FileNotFoundException

红尘浮屠 2016-03-02 08:09:24
抓狂了,求个大神解决下问题,查了一整天也没弄懂到底发生了什么问题。
剧情如下:
首先,我通过IIS发布了服务器,服务器地址: http://10.6.94.170/CreateServices/Service1.asmx
这个地址我通过模拟器中的游览器可以直接访问。但是在安卓代码中就出现这个异常了
异常:
03-02 11:52:37.981 18005-18059/first2.hc.tess W/System.err: java.io.FileNotFoundException: http://10.6.94.170/CreateServices/Service1.asmx
03-02 11:52:37.981 18005-18059/first2.hc.tess W/System.err: at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
03-02 11:52:37.981 18005-18059/first2.hc.tess W/System.err: at first2.hc.tess.MainActivity.GetStudentService(MainActivity.java:103)
03-02 11:52:37.981 18005-18059/first2.hc.tess W/System.err: at first2.hc.tess.MainActivity$2.run(MainActivity.java:61)

游览器和模拟器访问时获取的片段如下:
POST /CreateServices/Service1.asmx HTTP/1.1
Host: 10.6.94.170
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/selectAllStudentInfor"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<selectAllStudentInfor xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope>


HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<selectAllStudentInforResponse xmlns="http://tempuri.org/">
<selectAllStudentInforResult>
<Student>
<Name>string</Name>
<Number>string</Number>
</Student>
<Student>
<Name>string</Name>
<Number>string</Number>
</Student>
</selectAllStudentInforResult>
</selectAllStudentInforResponse>
</soap:Body>
</soap:Envelope>


下面是我的安卓测试代码:
 public void GetStudentService() {

String ServerUrl = "http://10.6.94.170/CreateServices/Service1.asmx";
//soapAction = 命名空间 + 方法名
String soapAction = "http://tempuri.org/selectAllStudentInfor";
//拼凑requestData
String soap = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ "<soap:Body>";
String mreakString = "";
mreakString = "<selectAllStudentInfor xmlns=\"http://tempuri.org/\">";
String soap2 = "</soap:Body> </soap:Envelope>";
String requestData = soap + mreakString + soap2;
//其上所有的数据都是在拼凑requestData,即向服务器发送的数据
try {
URL url = new URL(ServerUrl); //指定服务器地址
HttpURLConnection con = (HttpURLConnection) url.openConnection();//打开链接
byte[] bytes = requestData.getBytes("utf-8"); //指定编码格式,可以解决中文乱码问题
con.setDoInput(true); //指定该链接是否可以输入
con.setDoOutput(true); //指定该链接是否可以输出
con.setUseCaches(false); //指定该链接是否只用caches
con.setConnectTimeout(6000); // 设置超时时间
con.setRequestMethod("POST"); //指定发送方法名,包括Post和Get。
con.setRequestProperty("Content-Type", "text/xml;charset=utf-8"); //设置(发送的)内容类型
con.setRequestProperty("SOAPAction", soapAction); //指定soapAction
con.setRequestProperty("Content-Length", bytes.length + ""); //指定内容长度

//发送数据
OutputStream outStream = con.getOutputStream();
outStream.write(bytes);
// if(con.getResponseCode() == 200){
//获取数据
InputStream inputStream = con.getInputStream();
String text = Utils.getTextFromStream(inputStream);


我怀疑可能是.asmx这个不能访问,具体原因就不知道了,求各位大神解决。救命啊,抓狂死了!
...全文
2882 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
tcmakebest 2016-03-28
  • 打赏
  • 举报
回复
用IE打开网址看是否能够访问: http://10.6.94.170/CreateServices/Service1.asmx 能够访问的情况下,点击selectAllStudentInfor方法查看详细的内容是否和楼主的相同. 另外楼主连接服务器的代码也太乱了,上网找一份能调用HTTP POST的就行.
dy13142013 2016-03-27
  • 打赏
  • 举报
回复
同求啊,大神们
红尘浮屠 2016-03-03
  • 打赏
  • 举报
回复
有没有人啊!!
jklwan 2016-03-03
  • 打赏
  • 举报
回复
你这个是webservice,不能用这种HttpURLConnection请求方式,需要用ksoap2-android这个包来请求才行

80,351

社区成员

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

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