7610 网络连接需要什么特殊处理吗?

jjxoyzy 2009-12-02 10:53:18
7610 网络连接需要什么特殊处理吗?

public static int debug;
public static String getMessageHttpConnection(String url)
{

HttpConnection c = null;
InputStream is = null;
int rc = 0;
String str = "";
try
{

debug=0;
System.out.println("cnecting...........");
try
{
c = (HttpConnection) Connector.open(url);
rc = c.getResponseCode();
c = null;
c = (HttpConnection) Connector.open(url);
rc = c.getResponseCode();
debug=1;
}
catch (IOException e)
{

System.out.println("cmnet is fiail");
try
{
debug=2;
c = null;
c = (HttpConnection) Connector.open("http://10.0.0.172:80/lottery/wap/issue_info.htm", Connector.READ, true);
c.setRequestProperty("X-Online-Host", "http://caipiao.wap.taobao.com");
c.getResponseCode();
c = null;
c = (HttpConnection) Connector.open("http://10.0.0.172:80/lottery/wap/issue_info.htm", Connector.READ, true);
c.setRequestProperty("X-Online-Host", "http://caipiao.wap.taobao.com");
rc = c.getResponseCode();
debug=3;

}
catch (Exception ex)
{
debug=4;
System.out.println("cmwap is fiali");
str="";
GameScreen.isNotic = true;
}
}
try
{
if( rc == HttpConnection.HTTP_OK )
{

is = c.openInputStream();
data = new byte[832];
int actual = 0;
int bytesread = 0;
while ((bytesread != data.length) && (actual != -1))
{
actual = is.read(data, bytesread, data.length - bytesread);
bytesread += actual;
}
c.close();
is.close();
str = new String(data, "utf-8");
System.out.println("conect is ok");
debug=5;
}
else
{
debug=6;
str="";
System.out.println("conect is falil");
GameScreen.isNotic = true;
}
}
catch (IOException e)
{
str="";
System.out.println("conect is falil");
e.printStackTrace();
GameScreen.isNotic = true;
}
debug=7;
}
catch (Exception e)
{
// TODO: handle exception
str="";
GameScreen.mid.destroyApp(true);
e.printStackTrace();
}
debug=8;
return str;
}





其他手机连接网络不管cmnet还是cmwat接入都没问题,但是为什么在nokia7610上面就 报错:


7610 连接网络 信息:

1. 在debug =0 处 运行很久 ,然后 在debug=2 处 报错!!! 获取不到返回的string

2.手机上其他软件可以接入网络 例如qq。
...全文
101 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jjxoyzy 2009-12-02
  • 打赏
  • 举报
回复
第一 你没处理移动计费提示页面,

第二 你没处理cmnet cmwat 两种不同的联网方式

你的联网跟我开始连接没任何区别,我连接的时候 ,在debug =0 就已经卡住了!但还是谢谢你的热心回答!!
pjw100 2009-12-02
  • 打赏
  • 举报
回复
第二种方式:
public static String SendPost(String url, String request) {
String xml = "";
try {
HttpConnection conn = (HttpConnection) Connector.open(url, Connector.READ_WRITE);
conn.setRequestMethod(HttpConnection.POST);
conn.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.1");
conn.setRequestProperty("Content-Language", "en-US");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
byte[] postMsg = request.getBytes("UTF-8");
conn.setRequestProperty("Content-Length", Integer.toString(postMsg != null ? postMsg.length : 0));

OutputStream out = conn.openOutputStream();
out.write(postMsg);
InputStream in = conn.openInputStream();
DataInputStream dis = new DataInputStream(in);
int ch = 0;
StringBuffer b = new StringBuffer();
while ((ch = dis.read()) != -1) {
b.append((char) ch);
}
xml = b.toString();
} catch (IOException ex) {
ex.printStackTrace();
}
System.out.println(xml);
return xml;
}
pjw100 2009-12-02
  • 打赏
  • 举报
回复
public static String getXml(String url) {
String content = null;
try {
HttpConnection hc = (HttpConnection) Connector.open(url);
InputStreamReader isr = new InputStreamReader(hc.openInputStream(), "UTF-8");
int ic;
StringBuffer b = new StringBuffer();
while ((ic = isr.read()) != -1) {
b.append((char) ic);
}
isr.close();
hc.close();
content = b.toString();
} catch (Exception e) {
}
System.out.println(content);
return content;
}
pjw100 2009-12-02
  • 打赏
  • 举报
回复
HttpConnection类分有两种请求方式GET和POST.

13,100

社区成员

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

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