我注意到,在响应中设置后,默认情况下会使用unirest java库cookie发送请求(就像任何浏览器一样)。有什么方法可以避免吗?
示例:
public class Main {
private static HttpResponse<JsonNode> doRequest() throws UnirestException {
try {
HttpResponse<JsonNode> jsonResponse = Unirest
.get("http://example.com")
.header("Accept", "application/json").asJson();
return jsonResponse;
} catch (UnirestException e) {
throw e;
}
}
public static void main(String[] args) throws UnirestException {
//first request receive a set-cookie header in response
doRequest();
//second request send a Cookie header with the cookie set by the first one: can I avoid this?
doRequest();
}
}
答案 0 :(得分:1)
看起来像
Unirest.config().enableCookieManagement(false);
解决了问题。