【发布时间】:2010-11-30 03:54:33
【问题描述】:
我正在尝试向需要 cookie 的网页发出请求。我正在使用 HTTPUrlConnection,但响应总是回来说
<div class="body"><p>Your browser's cookie functionality is turned off. Please turn it on.
如何发出请求,使被查询的服务器认为我打开了 cookie。我的代码是这样的。
private String readPage(String page) throws MalformedURLException {
try {
URL url = new URL(page);
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
uc.connect();
InputStream in = uc.getInputStream();
int v;
while( (v = in.read()) != -1){
sb.append((char)v);
}
in.close();
uc.disconnect();
} catch (IOException e){
e.printStackTrace();
}
return sb.toString();
}
【问题讨论】:
标签: java http-headers