国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
移動資費提示過濾
最近移動對網(wǎng)關(guān)進行改造,會彈出一個資費提示的wap頁面,干擾了眾多手機應用,手機網(wǎng)絡(luò)游戲的正常運行,僅提供一個移動資費提示過濾的工具類代碼,以拋磚引玉
Java代碼 
package redduke.game.j2me.io;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
public class HttpUtil{
/*
* 缺省過濾器實例
*/
protected static HttpConnectionFilter filter=new HttpConnectionFilter()
{
public boolean accept(HttpConnection con) {
/* 資費提示wap頁面長度=438+目的地URL字符串字節(jié)長度 */
return con!=null && con.getLength()!=438+con.getURL().getBytes().length;
}
};
/**
* 打開一個HttpConnection
* @param url
*/
public static HttpConnection open(final String url)
{
/* 一個HttpConnection的代理實現(xiàn) */
return new HttpConnection()
{
/*
* 連接
*/
private javax.microedition.io.HttpConnection con;
/*
* 連接次數(shù),超過次數(shù)則認為連接失敗
*/
private int connectCount=0;
/*
* 輸出緩沖
*/
private ByteArrayOutputStream baos=new ByteArrayOutputStream(1024);
/*
* 請求屬性
*/
private Hashtable requestProperties=new Hashtable();
/*
* 請求方式
*/
private String method=GET;
/*
* 連接服務器
*/
private void connect()
{
try
{
if(this.con!=null)
this.con.close();
}
catch(Exception ex){}
try
{
this.con=(javax.microedition.io.HttpConnection)Connector.open(url);
this.con.setRequestMethod(this.method);
Enumeration propertyKeys=this.requestProperties.keys();
while(propertyKeys.hasMoreElements())
{
String propertyKey=(String)propertyKeys.nextElement();
String propertyValue=(String)requestProperties.get(propertyKey);
this.con.setRequestProperty(propertyKey,propertyValue);
}
}
catch(Exception ex)
{
this.con=null;
}
}
/*
* 確認連接
*/
private void ensureConnect()
{
while(this.con==null || filter!=null && !filter.accept(this.con))
{
if(connectCount>=5)
throw new RuntimeException("Connection failed");
connectCount++;
this.connect();
}
}
public long getDate() throws IOException {
ensureConnect();
return this.con.getDate();
}
public long getExpiration() throws IOException {
ensureConnect();
return this.con.getExpiration();
}
public String getFile() {
ensureConnect();
return this.con.getFile();
}
public String getHeaderField(String arg0) throws IOException {
ensureConnect();
return this.con.getHeaderField(arg0);
}
public String getHeaderField(int arg0) throws IOException {
ensureConnect();
return this.con.getHeaderField(arg0);
}
public long getHeaderFieldDate(String arg0, long arg1) throws IOException {
ensureConnect();
return this.con.getHeaderFieldDate(arg0, arg1);
}
public int getHeaderFieldInt(String arg0, int arg1) throws IOException {
ensureConnect();
return this.con.getHeaderFieldInt(arg0, arg1);
}
public String getHeaderFieldKey(int arg0) throws IOException {
ensureConnect();
return this.con.getHeaderFieldKey(arg0);
}
public String getHost() {
ensureConnect();
return this.con.getHost();
}
public long getLastModified() throws IOException {
ensureConnect();
return this.con.getLastModified();
}
public int getPort() {
ensureConnect();
return this.con.getPort();
}
public String getProtocol() {
ensureConnect();
return this.con.getProtocol();
}
public String getQuery() {
ensureConnect();
return this.con.getQuery();
}
public String getRef() {
ensureConnect();
return this.con.getRef();
}
public String getRequestMethod() {
ensureConnect();
return this.con.getRequestMethod();
}
public String getRequestProperty(String arg0) {
ensureConnect();
return this.con.getRequestProperty(arg0);
}
public int getResponseCode() throws IOException {
ensureConnect();
return this.con.getResponseCode();
}
public String getResponseMessage() throws IOException {
ensureConnect();
return this.con.getResponseMessage();
}
public String getURL() {
ensureConnect();
return this.con.getURL();
}
public void setRequestMethod(String arg0) throws IOException {
this.method=arg0;
}
public void setRequestProperty(String arg0, String arg1) throws IOException {
requestProperties.put(arg0, arg1);
}
public String getEncoding() {
ensureConnect();
return this.con.getEncoding();
}
public long getLength() {
ensureConnect();
return this.con.getLength();
}
public String getType() {
ensureConnect();
return this.con.getType();
}
public DataInputStream openDataInputStream() throws IOException {
ensureConnect();
return this.con.openDataInputStream();
}
public InputStream openInputStream() throws IOException {
ensureConnect();
return this.con.openInputStream();
}
public void close() throws IOException {
ensureConnect();
this.con.close();
}
public DataOutputStream openDataOutputStream() throws IOException {
return new DataOutputStream(baos);
}
public OutputStream openOutputStream() throws IOException {
return baos;
}
};
}
/*
* 設(shè)置過濾器,可設(shè)置自定義過濾器
*/
public static void setHttpConnectionFilter(HttpConnectionFilter filter)
{
HttpUtil.filter=filter;
}
/**
* 過濾器接口
*/
public static interface HttpConnectionFilter
{
boolean accept(HttpConnection con);
}
}
使用例子
Java代碼 
HttpConnection con=HttpUtil.open("http:\\abc.com");
本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
java使用SAE中文分詞服務
java根據(jù)地址從百度API獲取經(jīng)緯度
java HttpConnection 調(diào)用.NET WebService
JAVA讀取WORD,EXCEL,PDF,TXT,RTF,HTML文件文本內(nèi)容的方法
java 下載網(wǎng)頁
Java實現(xiàn)在線預覽–openOffice實現(xiàn)
更多類似文章 >>
生活服務
分享 收藏 導長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服