13,100
社区成员
发帖
与我相关
我的任务
分享
package com.baibao;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.*;
public class Down extends Form implements CommandListener{
Command open;
StringItem si;
StringBuffer sb = new StringBuffer();
public Down(String arg0) {
super(arg0);
open=new Command("连接1",1,1);
si=new StringItem("输出:","");
this.addCommand(open);
this.append(si);
this.setCommandListener(this);
}
String url="http://xdown.monternet.com/portalapp/ms?ContentID=0105755200";
public void commandAction(Command cmd, Displayable form) {
if(cmd==open){
setText("打开链接:"+url);
connection(url);
// new Thread(new Runnable(){
// public void run(){
// try {
//
// postViaHttpConnection(url);
// } catch (IOException e) {
// //TODO 自动生成 catch 块
// displayAlert("command try", e.toString());
// }
// }
// }).start();
}
}
public void connection(final String url) {
new Thread(new Runnable() {
public void run() {
HttpConnection httpConn = null;
// InputStream iis = null;
InputStreamReader is = null;
try {
httpConn = (HttpConnection)Connector.open("http://10.0.0.172:80/portalapp/ms?ContentID=0105755200",
Connector.READ,true);
httpConn.setRequestProperty("X-Online-Host", "xdown.monternet.com");
httpConn.setRequestProperty("User-Agent", System.getProperty("microedition.profiles"));
// is=new InputStreamReader(httpConn.openInputStream(),"utf-8");
// read(is);
setText("get:" + httpConn.getResponseCode());
httpConn.close();
} catch (Exception e) {
displayAlert("Error2!", e.toString()+" "+sb.toString());
}
}
}).start();
}
public void displayAlert(String tile,String data){
Alert alert = new Alert(tile, data, null,
AlertType.ERROR);
alert.setTimeout(Alert.FOREVER);
Display.getDisplay(MainMIDlet.instance).setCurrent(alert);
}
public void setText(String str){
sb.append("*/"+str+"\n");
si.setText(sb.toString());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head>
<meta http-equiv="Content-type" content="text nd.wap.wml"/>
</head>
<card id="main" title="游戏频道">
<p>系统忙,请稍后再试!</p>
<p><br/></p>
<p>
<anchor title="返回"><prev/>返回</anchor>
</p>
<p>
<a href="http://gamepie.i139.cn/wap/index.jsp" title="游戏频道">
游戏频道
</a>
<br/>
<img alt="" src="/portalapp/wml/images/clock.gif"/>X时刻10:54
</p>
</card>
</wml>