我正在尝试向需要cookie的网页发出请求.我正在使用HTTPUrlConnection,但响应总是回来说
<div class="body"><p>Your browser's cookie functionality is turned off. Please turn it on.
Run Code Online (Sandbox Code Playgroud)
我如何发出请求,以便查询的服务器认为我已打开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();
}
Run Code Online (Sandbox Code Playgroud)