J2ME 在线等高手 HttpConnection 遇到302

丁码农
博客专家认证
2012-04-21 04:24:15
模拟器下可以正常请求/响应。部署到真机(诺基亚5230 E72等)之后无法正确响应。尤其是在E72中连异常信息都不见了。

贴一下代码:

public static String getHeaderFieldNewURL(String url) throws Exception{

try {
HttpConnection conn = (HttpConnection) Connector.open(url,Connector.READ_WRITE);
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
conn.setRequestMethod(HttpConnection.POST);
//conn.setFollowRedirects();
int responseCode =conn.getResponseCode();//

//302 Redirect
if(responseCode==HttpConnection.HTTP_MOVED_TEMP){
String newUrl =conn.getHeaderField("Location");//new_uri is null on some devices
conn.close();
return newUrl;
}else{
conn.close();
return "";
}

} catch (Exception e) {
//throw new Exception("Response status not OK");
e.printStackTrace();
return null ;
}


这段代码,是为了获取“将要跳转到的新地址”(然后我在另一个方法里面,重新发送请求到新的url去)。因为我怕某些设备不能正确的支持“自动跳转”。之前在模拟器测试通过,可是到了真机环境完全不行。聪明反被聪明误。
J2ME真机调试又很麻烦。请各位高手帮忙!!!
...全文
91 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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