佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 839|回复: 1

J2ME 怎么拿WAP SITE的东西??

[复制链接]
发表于 3-1-2008 12:35 PM | 显示全部楼层 |阅读模式
就很普通的

try {
                        // Open up a http connection with the Web server
                        // for both send and receive operations
                        hc = (HttpConnection)Connector.open(url);
                        
                        // Set the request method to POST
                        hc.setRequestMethod(HttpConnection.GET);
                        
                        // Getting the response code will open the connection,
            // send the request, and read the HTTP response headers.
            // The headers are stored until requested.
            rc = hc.getResponseCode();
                        
            if (rc != HttpConnection.HTTP_OK) {
                throw new IOException("HTTP response code: " + rc);
            }

                        // Retrieve the response back from the servlet
                        dis = new DataInputStream(hc.openInputStream());
                        
                        
                        int ch;
                        // Check the Content-Length first
                        long len = hc.getLength();
                        
                        if(len!=-1)
                        {
                                for(int i = 0;i<len;i++)
                                {                                
                                        if((ch = dis.read())!= -1)
                                        {                                       
                                                messagebuffer.append((char)ch);
                                        }
                                        else
                                        {
                                                // if the content-length is not available
                                                while ((ch = dis.read()) != -1)
                                                        messagebuffer.append((char) ch);
                                        }
                                }
                        }
                        dis.close();
                } catch (IOException ioe) {
                        messagebuffer = new StringBuffer("ERROR!");
                } finally {
                        // Free up i/o streams and http connection
                        try {
                                if (hc != null) hc.close();
                        } catch (IOException ignored) {}
                        try {
                                if (dis != null) dis.close();
                        } catch (IOException ignored) {}
                        try {
                                if (dos != null) dos.close();
                        } catch (IOException ignored) {}
                }
               
                content = messagebuffer.toString();
                    }
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 3-1-2008 12:36 PM | 显示全部楼层
至于我open的url

url = "http://wap.yahoo.com/";
url = "http://www.yahoo.com/";

www.的,我拿到reponsecode 200, 也拿得到它的content。

但是,wap.的,我拿到reponsecode 200,不过,却拿不到它的content, 就连check 它的 length 也得到 -1。

为什么这样的?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 20-10-2025 02:17 AM , Processed in 0.107201 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表