查看: 839|回复: 1
|
J2ME 怎么拿WAP SITE的东西??
[复制链接]
|
|
就很普通的
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();
} |
|
|
|
|
|
|
|

楼主 |
发表于 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。
为什么这样的? |
|
|
|
|
|
|
| |
本周最热论坛帖子
|