ATCMCC—移动随身E行–CMCC无线宽带–手机客户端(beta)
…
这个是弄了两天的东西..
大部分时间卡在那个Source类里面了..
虽然是以前做过的...
import java.io.InputStream;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.Image;
/**
* 下载网页内容
*
* @author princehaku
*/
public class Source {
/** 存放cookie
*/
public static String cookieString = “”;
/**联网方式
*/
static int connectType = 1;
/**
* url
*
* @param url
* 提交地址
* @param type
* 联网方式
* 1————-cmnet
* 2————-wap
* @return Image 图片
*/
public Image getImg(String url, int type) throws Exception {
connectType = type;
//String line = “”;
String content = “”;
// System.out.println(Inc.cookieString);
HttpConnection httpConn = null;
try {
System.out.println(url);
if (type == 1) {
System.out.println(“cmnet”);
httpConn = (HttpConnection) Connector.open(url, Connector.READ_WRITE,
true);
} else {
System.out.println(“cmwap”);
httpConn = (HttpConnection) Connector.open(“http://10.0.0.172/” + url.substring(url.indexOf(“/”, url.indexOf(“//”) + 2) + 1, url.length()), Connector.READ, true);
httpConn.setRequestProperty(“X-Online-Host”, url.substring(url.indexOf(“//”) + 2, url.indexOf(“/”, url.indexOf(“//”) + 2)));
httpConn.setRequestProperty(“User-Agent”, System.getProperty(“microedition.profiles”));
httpConn = (HttpConnection) Connector.open(“http://10.0.0.172/” + url.substring(url.indexOf(“/”, url.indexOf(“//”) + 2) + 1, url.length()), Connector.READ, true);
httpConn.setRequestProperty(“X-Online-Host”, url.substring(url.indexOf(“//”) + 2, url.indexOf(“/”, url.indexOf(“//”) + 2)));
httpConn.setRequestProperty(“User-Agent”, System.getProperty(“microedition.profiles”));
}
//httpConn.setConnectTimeout(30000);
//httpConn.setReadTimeout(30000);
//httpConn.setRequestMethod(“POST”);
//httpConn.setRequestProperty(“Host”,url.substring(url.indexOf(“http://”),url.indexOf(“:”)+1));
httpConn.setRequestProperty(“User-Agent”, “Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 FBSMTWB”);
httpConn.setRequestProperty(“Accept”, “text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8”);
httpConn.setRequestProperty(“Referer”, url);
//httpConn.setRequestProperty(“Accept-Encoding”, “gzip,deflate”);
httpConn.setRequestProperty(“Accept-Charset”, “GB2312,utf-8;q=0.7,*;q=0.7”);
//httpConn.setRequestProperty(“Accept-Charset”, “GB2312,utf-8;q=0.7,*;q=0.7”);
if (!(Source.cookieString.equals(“”))) {
// 晕死..
httpConn.setRequestProperty(“Cookie”, “” + Source.cookieString + “;”);
System.out.print(“send cookie=======”+cookieString);
}
//httpConn.setRequestProperty(“Keep-Alive”, “300”);
httpConn.setRequestProperty(“Connection”, “keep-alive”);
//httpConn.setRequestProperty(“Cache-Control”, “no-cache”);
//System.out.println(httpConn.getResponseMessage());
InputStream uurl = httpConn.openInputStream();
if (httpConn.getHeaderField(“Set-Cookie”) != null) {
String set_Cookie = httpConn.getHeaderField(“Set-Cookie”);
System.out.println(“get cookie” + set_Cookie);
Source.cookieString = set_Cookie.substring(0, set_Cookie.indexOf(“;”));
//System.out.println(httpConn.getHeaderField(“Timestamp”));
}
//InputStreamReader br=new InputStreamReader(uurl, encode);
System.out.println(“getverifyimg”);
return Image.createImage(uurl);
} catch (Exception e) {
// System.out.println(e.getMessage());
content = “Error : “;
content += e.getMessage();
throw new Exception(e.getMessage());
//return content;
} finally {
//System.out.println(content);
//uurl.close();
//httpConn.close();
}
}
}
只给出部分..
哎….
不过总算可以用了…
虽然有小问题..比如验证码和认证失败的检测…
因为超时的原因暂时不弄了…
等以后再弄…
现在准备搞个桌面版的…
一直开个chrome不安逸得…