【发布时间】:2015-12-22 10:43:56
【问题描述】:
我正在使用 org.apache.httpcomponents.httpclient 发送带有 cookie 的 http 请求:
```
URI uri = new URIBuilder().setScheme("https").setHost("api.weibo.com").setPath("/oauth2/authorize").setParameter("client_id","3099336849").setParameter("redirect_uri","http://45.78.24.83/authorize").setParameter("response_type", "code").build();
HttpGet req1 = new HttpGet(uri);
RequestConfig config = RequestConfig.custom().setRedirectsEnabled(false).build();
req1.setConfig(config);
req1.setHeader("Connection", "keep-alive");
req1.setHeader("Cookie", cookie);
req1.setHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36");
response = httpclient.execute(req1);
```
我搜索了很多并尝试启用/禁用自动重定向,但它似乎对我不起作用。那么有人可以告诉我如何像浏览器一样获取位置标头作为响应吗?
【问题讨论】:
-
请分享您用于尝试禁用重定向的代码。
标签: java http apache-httpcomponents