关于cmwap的代理
来源:互联网 发布:js复杂数据类型 编辑:程序博客网 时间:2024/06/06 09:35
在实际的J2ME网络编程中,一般需要提供以CMWAP代理的方式连接网络,在J2ME中,连接的代码和直接连接有所不同,代码如下:
HttpConnection http = (HttpConnection)Connector.open(("http://10.0.0.172/"+url);
http.setRequestProperty("X-Online-Host",ServerName);
例如你需要访问的地址为:
http://www.test.com/login/loginServlet
则上面的代码就为:
HttpConnection http = (HttpConnection)Connector.open((http://10.0.0.172/+”login/loginServlet”);
http.setRequestProperty("X-Online-Host",”www.test.com”);
在实际使用过程中,只需要使用实际需要访问的地址的域名或者IP来代替ServerName,例如示例中的“www.test.com”,使用后续的地址类代替代码中的url,例如示例中的“login/loginServlet”,就可以实际的使用CMWAP代理来进行连接了。
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
在反编译了数个J2ME游戏以及UCSDK之后,发现Http请求都使用到了cmwap代理,而代码几乎同上。
J2ME发起请求,并且获得返回数据:
/** * * @param host IP + port 如 125.69.106.132:8099 (不要加http://) * @param url /sk/payServlet (以/开头) * @param cmwap 是否使用cmwap接入(是否开启代理) * @throws IOException */ private static void URLRequest(String host, String url, boolean cmwap) throws IOException { HttpConnection c = null; InputStream is = null; int rc; try { if (cmwap) { c = (HttpConnection) Connector.open("http://10.0.0.172:80" + url, 3, true); c.setRequestProperty("X-Online-Host", host); c.setRequestProperty("Accept", "*/*"); } else { c = (HttpConnection) Connector.open("http://" + host + url, 3, true); } OutputStream openOutputStream = c.openOutputStream(); openOutputStream.write("Vicky".getBytes()); openOutputStream.flush(); openOutputStream.close(); rc = c.getResponseCode(); if (rc != HttpConnection.HTTP_OK) { throw new IOException("HTTP response code: " + rc); } is = c.openInputStream(); String type = c.getType(); int len = (int) c.getLength(); if (len > 0) { int actual = 0; int bytesread = 0; byte[] data = new byte[len]; while ((bytesread != len) && (actual != -1)) { actual = is.read(data, bytesread, len - bytesread); bytesread += actual; } String msg = new String(data,"UTF-8"); System.out.println("MSG>>>>>>>>>>>" + msg); } } catch (ClassCastException e) { throw new IllegalArgumentException("Not an HTTP URL"); } finally { if (is != null) { is.close(); } if (c != null) { c.close(); } } }
Servlet获得请求处理,并返回数据。
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { byte[] bufer = new byte[256]; ServletInputStream inputStream = request.getInputStream(); inputStream.read(bufer); inputStream.close(); String getMsg = new String(bufer,"UTF-8"); System.out.println("getMsg = " + getMsg); byte[] msg = "Hello World".getBytes(); response.setContentLength(msg.length); response.setCharacterEncoding("UTF-8"); ServletOutputStream outputStream = response.getOutputStream(); outputStream.write(msg); outputStream.flush(); outputStream.close(); }
- 关于cmwap的代理
- 关于接入点,cmwap,代理设置,WIFI
- 关于接入点,cmwap,代理设置,WIFI
- 关于cmwap和cmnet之间的区别
- 关于cmwap和gzip
- 一个关于CMNET和CMWAP流量费的解释
- 使用Socket连接穿越CMWAP代理与完整的HTTP通信步骤7步
- ksoap2-android访问webservice,当网络有代理的情况(cmwap)
- 使用Socket连接穿越CMWAP代理
- 使用Socket连接穿越CMWAP代理
- 使用Socket连接穿越CMWAP代理
- 如何穿透CMWAP代理封锁(收集)
- 关于利用CMWAP的方式不能通过TCP/IP连接INTERNET的说明!
- 关于GPRS(cmnet、cmwap)和CDMA 1X的比较及最优方案
- cmwap和cmnet的网速
- CMWAP和CMNET的区别
- cmwap与cmnet的区别
- cmnet和cmwap的区别
- 广州住房公积金提取、变更的步骤
- Linux 动态库 so 使用
- Android组件间通信机制对面向对象特性的影响
- iOS开发之异步加载图片
- 在SQL Server中实现高可用性AlwaysOn
- 关于cmwap的代理
- ftl文件是什么文件
- C语言实验题——数字串求和
- Protect your eyes, NOW!
- windows无法连接到user profile service服务。此问题阻止标准用户登录系统
- 创建网页背景材质时常用到的4种方法
- mmap coredump
- C# 控件命名规范
- 指针&引用