Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

发送给代理服务器的HTTP请求行的格式该如何写? #999

Closed
Shawnul opened this issue Jul 26, 2022 · 11 comments
Closed

发送给代理服务器的HTTP请求行的格式该如何写? #999

Shawnul opened this issue Jul 26, 2022 · 11 comments

Comments

@Shawnul
Copy link

Shawnul commented Jul 26, 2022

作者好!
我学习了一下tutorial-05-http_proxy.md中代理服务器的相关内容。
设定监听端口号为1234,运行这个例子后,我在浏览器中设置好代理服务器地址后可以得到正确的结果。
我想自己用Postman模拟一下浏览器发送报文到代理服务器的过程,但是无法成功,想请教一下应该如何设置请求参数。
以下是我设置的postman格式:

Get http://www.sogou.com/ HTTP/1.1
Host:127.0.0.1:1234
User-Agent:Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8
Accept-Language:en-US,en;q=0.5
Accept-Encoding:gzip, deflate
Connection:keep-alive

还请指正

@Barenboim
Copy link
Contributor

Barenboim commented Jul 26, 2022

你好。发给代理的时候,Host要填写最终目标的:
Host: www.sogou.com
另外,我们这个proxy,你可以GET https的url, 所以,这么发也是对的:
GET https://www.sogou.com/ HTTP/1.1
Host: www.sogou.com
....

@Shawnul
Copy link
Author

Shawnul commented Jul 26, 2022

你好。发给代理的时候,Host要填写最终目标的: Host: www.sogou.com 另外,我们这个proxy,你可以GET https的url, 所以,这么发也是对的: GET https://www.sogou.com/ HTTP/1.1 Host: www.sogou.com ....

非常感谢!
但是我在思考如果这么写,那是如何发到代理服务器的啊(指我的本地运行的程序)

@Barenboim
Copy link
Contributor

啊,这个具体看Postman怎么用了。我也没有用过。

@Shawnul
Copy link
Author

Shawnul commented Jul 26, 2022

啊,这个具体看Postman怎么用了。我也没有用过。

那如果单纯从写程序的角度上来说,我想通过代理服务器获取资源,在create_http_task(const std::string& url,int redirect_max,int retry_max,http_callback_t callback)这一步,发送给代理服务器的url应该怎么写啊。。。

@Shawnul
Copy link
Author

Shawnul commented Jul 26, 2022

哦,我想到了,有一个有代理服务器url的接口。。。

@Shawnul
Copy link
Author

Shawnul commented Jul 26, 2022

非常感谢!

@Barenboim
Copy link
Contributor

啊,这个具体看Postman怎么用了。我也没有用过。

那如果单纯从写程序的角度上来说,我想通过代理服务器获取资源,在create_http_task(const std::string& url,int redirect_max,int retry_max,http_callback_t callback)这一步,发送给代理服务器的url应该怎么写啊。。。

这个也有,在我们的FAQ里,关于使用http proxy的那一条,其中的方法1。
#170

@Shawnul
Copy link
Author

Shawnul commented Jul 26, 2022

啊,这个具体看Postman怎么用了。我也没有用过。

那如果单纯从写程序的角度上来说,我想通过代理服务器获取资源,在create_http_task(const std::string& url,int redirect_max,int retry_max,http_callback_t callback)这一步,发送给代理服务器的url应该怎么写啊。。。

这个也有,在我们的FAQ里,关于使用http proxy的那一条,其中的方法1。 #170

好的好的

@Shawnul Shawnul closed this as completed Jul 26, 2022
@Shawnul Shawnul reopened this Jul 27, 2022
@Shawnul
Copy link
Author

Shawnul commented Jul 27, 2022

我还有点小问题
我想在发送HttpTask后的callback检测有是否发送成功,如果失败就重新发送,超过固定次数就返回
1.其中能否用create_http_task(const std::string& url,int redirect_max,int retry_max,http_callback_t callback)中retry_max设置重传次数
2.一个post方法,我想复制上一个http_task的req给当前http_task,下面的写法对不
protocol::HttpRequest* req = task->get_req();
/req->get_parsed_body(&body, &len);
req->append_output_body_nocopy(body, len);
/
*retrain_task->get_req() = std::move(*req);

@Barenboim
Copy link
Contributor

我还有点小问题
我想在发送HttpTask后的callback检测有是否发送成功,如果失败就重新发送,超过固定次数就返回
1.其中能否用create_http_task(const std::string& url,int redirect_max,int retry_max,http_callback_t callback)中retry_max设置重传次数
2.一个post方法,我想复制上一个http_task的req给当前http_task,下面的写法对不
protocol::HttpRequest* req = task->get_req();
/req->get_parsed_body(&body, &len); req->append_output_body_nocopy(body, len);/
*retrain_task->get_req() = std::move(*req);

1、可以用retry_max。但retry_max包括了connect,send,read等一切的错误。
2、应该没有什么问题。但根据C++对std::move的要求,被move出的对象,只保证可以被重新赋值(支持std::swap)和销毁。但是,不能对被move的对象再进行其它的操作。所以,你的原req最好不要再append了。

@Shawnul
Copy link
Author

Shawnul commented Jul 27, 2022

好的谢哥

@Shawnul Shawnul closed this as completed Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants