程序中通过wap联网方式访问网络

来源:互联网 发布:舰队collection知乎 编辑:程序博客网 时间:2024/05/29 17:57

http://bbs.csdn.net/topics/360145225


用户的联网方式大致有 wap net wifi 三种. 使用android包中提供的函数,HttpConnection只能使用net和wifi,wap方式无法访问. 

问? 如何让程序可以通过wap访问网络?
对我有用[0] 丢个板砖[0] 引用 | 举报 | 管理 | TOP
回复次数:12#1 得分:0回复于: 2011-04-10 17:09:13
call for answer.
专访方兴:Web应用将成企业未来开发趋势
对我有用[0] 丢个板砖[0] 引用 | 举报 | 管理 | TOP
#2 得分:0回复于: 2011-04-10 19:27:43
call for answer.
【免费】解读海外市场营销奥秘
对我有用[0] 丢个板砖[0] 引用 | 举报 | 管理 | TOP
#3 得分:0回复于: 2011-04-11 09:50:41
wap上网是要经过代理的,取得代理地址 设置代理
“Hadoop&BigData 技术赢门票”活动正式启动
对我有用[0] 丢个板砖[0] 引用 | 举报 | 管理 | TOP
#4 得分:10回复于: 2011-04-11 10:18:51
Java code?
1
2
3
4
5
6
7
8
if(bUsingProxy){
                conn.setRequestProperty("X-Online-Host", host);
            }
            conn.setRequestProperty("Accept""text/plain");
            conn.setRequestProperty("Content-Type""application/x-www-form-urlencoded");
            conn.setRequestProperty("Connection""Close");
            conn.setRequestProperty("Content-Length", String.valueOf(data.length));
            conn.connect();
对我有用[0] 丢个板砖[0] 引用 | 举报 | 管理 | TOP
#5 得分:20回复于: 2011-04-11 10:21:21
给个完整的
Java code?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
private void doPost() throws IOException{
         
        StringBuilder builder = new StringBuilder();
        builder.append("http://");
         
        if(bUsingProxy){
            builder.append(proxy);
        }else{
            builder.append(host);
        }
         
        if(urlpage != null){
            builder.append("/" + urlpage);
        }
         
        String desturl = builder.toString();
        InputStream stream = null
        HttpURLConnection conn = null;
        try{
            byte[] data = params.getBytes();
             
            URL url = new URL(desturl);
            conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
 
            conn.setConnectTimeout(connectTimeout);
            conn.setReadTimeout(readTimeout);
            conn.setDoOutput(true);
            conn.setUseCaches(false);
            if(bUsingProxy){
                conn.setRequestProperty("X-Online-Host", host);
            }
            conn.setRequestProperty("Accept""text/plain");
            conn.setRequestProperty("Content-Type""application/x-www-form-urlencoded");
            conn.setRequestProperty("Connection""Close");
            conn.setRequestProperty("Content-Length", String.valueOf(data.length));
            conn.connect();
             
            OutputStream outputStream = conn.getOutputStream();
            outputStream.write(data);
            outputStream.flush();
            outputStream.close();
             
            int resp_code = conn.getResponseCode();
            Map<String, List<String>> headerMap = conn.getHeaderFields();
            listener.action(NetworkListener.RESPONSE_CODE, new Integer(resp_code));
             
            if(resp_code == HttpURLConnection.HTTP_OK){
                stream = conn.getInputStream();
                if(stream != null){
                    Log.d("cn.cmcc.t""GETRESPONSE:" + resp_code);
                }
                if(mCommand != -1)
                    listener.action(NetworkListener.RECEIVE_STREAM, new Object[]{new Integer(mCommand),stream});
                else
                    listener.action(NetworkListener.RECEIVE_STREAM, stream);
            }
                 
        catch (IOException e) {
            e.printStackTrace();
            listener.action(NetworkListener.REQUEST_TIMEOUT, null);
        finally{
            if(stream != null)
                stream.close();
            if(conn != null)
                conn.disconnect();
        }
    }
对我有用[0] 丢个板砖[0] 引用 | 举报 | 管理 | TOP
#6 得分:10回复于: 2011-04-11 10:27:38
楼上那样做只能支持移动的cmwap吧 “X-Online-Host”只是移动私有的扩展头吧
对我有用[0] 丢个板砖[0] 引用 | 举报 | 管理 | TOP
#7 得分:0回复于: 2011-04-11 11:09:23
感谢上面两位, 以前搜这个问题的资料都不知道怎么搜. 因为搜android cmwap 全部是android操作的答案. 

现在知道用代理了. 就大体明白怎么做了.多谢两位. 
对我有用[0] 丢个板砖[0] 引用 | 举报 | 管理 | TOP
#8 得分:0回复于: 2011-04-11 11:32:59
楼主能告诉我,你说的三种方法中,net是如何上网的
对我有用[0] 丢个板砖[0] 引用 | 举报 | 管理 | TOP
#9 得分:0回复于: 2011-04-11 13:13:58
恩,感谢楼上两位,我已经实现了.  另外我还发现了一个要点:

就是不管原来网页是何编码方式,用了这个cmwap后都变成了utf8

另外,一点,联通的cmwap网关也是10.00.00.172 么? 如何获取cmwap的网关ip和端口呢? 

两位回来拿分的时候,帮忙解答一下. 
对我有用[0] 丢个板砖[0] 引用 | 举报 | 管理 | TOP
#10 得分:0回复于: 2011-04-11 13:16:12
引用 8 楼 drsmart 的回复:
楼主能告诉我,你说的三种方法中,net是如何上网的


额? net方式, 不用做其他设置,就照普通的来,就可以上网的.... 

我也很奇怪.
对我有用[0] 丢个板砖[0] 引用 | 举报 | 管理 | TOP
#11 得分:0回复于: 2011-04-11 13:37:43
android.net.Proxy.getHost(context);获取网关IP
android.net.Proxy.getPort(context);获得端口
对我有用[0] 丢个板砖[0] 引用 | 举报 | 管理 | TOP
#12 得分:0回复于: 2011-07-11 14:41:39
楼上的 谢谢了,


原创粉丝点击