从 Java 管理 ASP.NET 站点的会话 (Apache HttpClient)

发布于 2024-10-07 08:12:18 字数 764 浏览 5 评论 0原文

我想从只能从会话内访问的 ASP.NET 站点获取网页。我正在使用 Apache HttpClient。我首先打开网站的主页,然后搜索“目标”页面的链接,然后启动“目标”页面的 GET 请求。问题是,当我收到第二个 GET 请求的响应时,我总是得到相同的(第一个)页面。如果我使用 Firefox 或 Google Chrome 打开该网站,我会看到“目标”页面。

从服务器的第一个响应中,我得到以下标头:

HTTP/1.1 200 OK
Date: Sun, 12 Dec 2010 19:03:56 GMT
Server: Microsoft-IIS/6.0
Platform: Mobitel Pla.NET
Node: 4
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Set-Cookie: ASP.NET_SessionId=0vpgd055cifko3mnw4nkuimz; path=/
Cache-Control: no-cache, must-revalidate
Content-Type: text/html; charset=utf-8
Content-Length: 7032

我使用 WireShark 检查了流量,所有标头看起来都正常。我在第二个 GET 请求时将正确的 cookie 发送回服务器。

我正在使用 Apache HttpClient。我只有一个 DefaultHttpClient 实例,我将其重用于第二个请求。我有 BROWSER_COMPATIBILITY Cookie 政策。

有什么想法吗?

I want to fetch a web page from a ASP.NET site that is only accessible from within a session. I'm using Apache HttpClient. I first open the main page of the site, then I search for the link to the "goal" page, and then I fire up a GET request for the "goal" page. The problem is that when I get the response for the second GET request, I always get the same (first) page. If I open the site with Firefox or Google Chrome I get the "goal" page.

From the first response from the server I get the following headers:

HTTP/1.1 200 OK
Date: Sun, 12 Dec 2010 19:03:56 GMT
Server: Microsoft-IIS/6.0
Platform: Mobitel Pla.NET
Node: 4
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Set-Cookie: ASP.NET_SessionId=0vpgd055cifko3mnw4nkuimz; path=/
Cache-Control: no-cache, must-revalidate
Content-Type: text/html; charset=utf-8
Content-Length: 7032

I inspected the traffic with WireShark and all headers look OK. I send the correct cookie back to the server on the second GET request.

I'm using Apache HttpClient. I have only one instance of DefaultHttpClient and I reuse that for the second request. I have BROWSER_COMPATIBILITY Cookie Policy.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不弃不离 2024-10-14 08:12:18

您需要在所有进一步的请求中从客户端发回此标头(发回您收到的 cookie):

Cookie: ASP.NET_SessionId=0vpgd055cifko3mnw4nkuimz; // and all other cookies

这应该可以解决问题

You need send back this header from the client (send back the cookie you received) in all your further requests:

Cookie: ASP.NET_SessionId=0vpgd055cifko3mnw4nkuimz; // and all other cookies

That should do the trick

多像笑话 2024-10-14 08:12:18

我发现了我的愚蠢错误。

错误在于我向链接发送了第二个 GET 请求,而没有替换 & 字符代码。

例如:

/(0vpgd055cifko3mnw4nkuimz)/Mp.aspx?ni=1482&pi=72&_72_url=925b9749-b7c7-4615-9f1a-9b613c344c82

这是错误的,因为我发送 & 而不是 &

正确的方法是:

/(0vpgd055cifko3mnw4nkuimz)/Mp.aspx?ni=1482&pi=72&_72_url=925b9749-b7c7-4615-9f1a-9b613c344c82

I found my stupid mistake.

The mistake was that I was sending the second GET request to a link, without replacing the ampersand character codes.

Ex:

/(0vpgd055cifko3mnw4nkuimz)/Mp.aspx?ni=1482&pi=72&_72_url=925b9749-b7c7-4615-9f1a-9b613c344c82

That is wrong, because I send & instead of &

The RIGHT way to do it is:

/(0vpgd055cifko3mnw4nkuimz)/Mp.aspx?ni=1482&pi=72&_72_url=925b9749-b7c7-4615-9f1a-9b613c344c82
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文