当前位置:编程学习 > asp >>

我用j2me访问一个aspx 接口,没有返回需要的东西

我用j2me访问一个aspx 接口,本来需要返回的是一段xml格式的数据,程序在虚拟机上运行没有问题,但是放到手机上运行时,返回的是一段wml的源码,服务器上的代码并没有执行,是什么原因,aspx是另一方提供的,不能更改 public static String requestGET(String strHost, String strUrl, int netMode) throws IOException { HttpConnection hpc = null; DataInputStream dis = null; boolean newline = false; StringBuffer content=new StringBuffer(); try { hpc = (HttpConnection) Connector.open("http://" + strHost + "/"+ strUrl, Connector.READ, true); hpc.setRequestProperty("Accept", "*/*"); hpc.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Confirguration/CLDC-1.0"); hpc.setRequestProperty("Content-Language", "en-CA"); // 判断连接是否正常 int status = hpc.getResponseCode(); if (status == HttpConnection.HTTP_OK) { dis = new DataInputStream(hpc.openInputStream()); int character; while ((character = dis.read()) != -1) { if ((char) character == '\\') { newline = true; continue; } else { if ((char) character == 'n' && newline) { content.append("\n"); newline = false; } else if (newline) { content.append("\\").append((char) character); newline = false; } else { content.append((char) character); newline = false; } } } } catch (IOException e) { e.printStackTrace(); } finally { if (hpc != null) { hpc.close(); hpc = null; }if (dis != null) { dis.close(); } } String result = (decodeToUTF_8(content.toString())).trim(); return result; } 需要返回的数据格式: <?xml version="1.0" encoding="UTF-8" ?> <!-- published at 2012-08-29 09:53:53 --> <content><result>969775</result><date>2012-08-29 09:53:54</date></content> 在模拟器上运行正常 手机上运行时实际返回的内容: <!DOCTYPE wml PUBLIC "....." ......> <wml> <head> ....... <go href="这里显示的是我提交的链接地址及参数"></go> </wml>
追问:诺基亚httpConnection访问网络报error in HTTP operation

//url 是以IP的形式访问的
hpc = (HttpConnection) Connector.open(url, Connector.READ, true);
hpc.setRequestProperty("Accept", "*/*");
hpc.setRequestProperty("X-Online-Host", serverAdddress);
hpc.setRequestProperty("Content-Type", "text/html");对这方面不懂,初次接触,最后的contenttype是最后加上的,不加,其它手机也可以取得数据,加了还是可以,诺基亚手机加不加都不能;具体应该咋个设置呢,初学不懂哦,谢谢不是,原来asp返回的是一个xml,后来改成另一种形式的字符串了,第一个问题算是解决了,现在的问题是诺基亚部分手机不能通过http访问服务器,在上面设置requestproperty部分,不管咋个设置,在getResponseCode时都在报error in http operation这个异常出来,测试手机是nokia2730c,手机卡是移动的

我加了你的百度hi,我在那里向你请教嘛
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,