gpt4 book ai didi

java - 服务器cookie=空

转载 作者:行者123 更新时间:2023-12-01 15:59:39 29 4
gpt4 key购买 nike

我正在进行身份验证并收到空 cookie。我想存储这个 cookie,但服务器没有返回给我 cookie。但响应代码是 200 ok。

httpConn.setRequestProperty(
"Authorization",
"Basic " + Base64OutputStream.encodeAsString(
login.getBytes(), 0, login.getBytes().length, false, false));

String tmpCookie = httpConn.getHeaderField("set-cookie");

这是我的代码。

String login = username + ":" + password;

String base = "http://mysever/login";
HttpConnection httpConn = null;
httpConn = (HttpConnection)Connector.open(base);
// Setup HTTP Request to POST
httpConn.setRequestMethod(HttpsConnection.POST);
httpConn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
httpConn.setRequestProperty("Accept",
"text/html,application/xhtml+xml,application/xml,application/x-javascript,*/*;q=0.5 ");
//Add the authorized header.
httpConn.setRequestProperty("Authorization",
"Basic " + Base64OutputStream.encodeAsString(
login.getBytes(), 0, login.getBytes().length, false, false));

message = httpConn.getResponseMessage();
status = httpConn.getResponseCode();
tmpCookie = httpConn.getHeaderField("Set-Cookie");

EventLogger.logEvent(guid, status);

if (status == HttpConnection.HTTP_OK)
{
String tmpCookie = httpConn.getHeaderField("set-cookie");
authForm.append("\nConnected");
authForm.append("\n\nLogin Response:" + message +
"\nHTTP response code:" + status + "\nCookie: "
+ tmpCookie);
//getNewZipFile();
}
else if(status !=HttpConnection.HTTP_OK){
throw new IOException("HTTP response code: " + status);
}
httpConn.close();

最佳答案

你真的建立了联系吗?您的代码显示您设置了一个请求属性,然后立即尝试查找 header 值,但没有指示该请求实际上已发送。

如果您正在这样做(在这种情况下,更完整的代码将受到欢迎),您应该使用 Wireshark或类似的东西来了解网络流量的实际情况。

关于java - 服务器cookie=空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4283358/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com