gpt4 book ai didi

java - 发送 GET HTTPS 请求但收到 403 禁止响应,为什么?为什么?

转载 作者:行者123 更新时间:2023-12-01 05:44:13 25 4
gpt4 key购买 nike

各位 friend ,我也遇到了同样的问题 Send GET HTTPS request but get 403 forbidden response, why?

我的urlstring还包含https://..,但是,我无法理解Bruno的回答。

When you send an HTTP GET the request should be like this: GET /COVIWeb/gate/... HTTP/1.1 Host: ekp.truefriend.com Not: GET https://ekp.truefriend.com/COVIWeb/gate/... HTTP/1.1 (that's only for requests via a proxy, and doesn't apply to the HTTPS requests anyway.)

更新

我仍然没有取得任何成功:

java.lang.IllegalStateException:目标主机不得为空,或在参数中设置。

我的绝对URL:

https://www.stage.ceosace.com/platform/j_spring_cas_security_check?ticket=ST-14-J76iOk5aXQNrZBBUeIn3-cas

我的代码:

String url = "/platform/j_spring_cas_security_check?ticket=ST-14-J76iOk5aXQNrZBBUeIn3-cas";

HttpGet request = new HttpGet(url);
request.setHeader("Accept", "*/*");
request.setHeader("User-Agent", USER_AGENT);
request.setHeader("connection","keep-alive");
request.setHeader("Host","Host:www.stage.ceosace.com"+":443");

我不知道我错在哪里;有什么建议吗?

最佳答案

Bruno 的回答说,包含主机名的 URL 形式很尴尬,而且可能是有问题的;主机名必须包含在Host: header 中。在完整 URI 中包含主机名会重复信息,并且可能有害(即使 RFC 声明 HTTP 1.1 服务器应准备好接受 URI 中的完整主机名)。

RFC 2616 Section 5.1.2有完整的详细信息:

The absoluteURI form is REQUIRED when the request is being made to a
proxy. The proxy is requested to forward the request or service it
from a valid cache, and return the response. Note that the proxy MAY
forward the request on to another proxy or directly to the server
specified by the absoluteURI. In order to avoid request loops, a
proxy MUST be able to recognize all of its server names, including
any aliases, local variations, and the numeric IP address. An example
Request-Line would be:

GET http://www.w3.org/pub/WWW/TheProject.html HTTP/1.1

To allow for transition to absoluteURIs in all requests in future
versions of HTTP, all HTTP/1.1 servers MUST accept the absoluteURI
form in requests, even though HTTP/1.1 clients will only generate
them in requests to proxies.

The authority form is only used by the CONNECT method (section 9.9).

The most common form of Request-URI is that used to identify a
resource on an origin server or gateway. In this case the absolute
path of the URI MUST be transmitted (see section 3.2.1, abs_path) as
the Request-URI, and the network location of the URI (authority) MUST
be transmitted in a Host header field. For example, a client wishing
to retrieve the resource above directly from the origin server would
create a TCP connection to port 80 of the host "www.w3.org" and send
the lines:

GET /pub/WWW/TheProject.html HTTP/1.1
Host: www.w3.org

followed by the remainder of the Request. Note that the absolute path
cannot be empty; if none is present in the original URI, it MUST be
given as "/" (the server root).

关于java - 发送 GET HTTPS 请求但收到 403 禁止响应,为什么?为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6327405/

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