zhllxt / asio2

Header only c++ network library, based on asio,support tcp,udp,http,websocket,rpc,ssl,icmp,serial_port,socks5.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

http client使用ip请求报错

xiaonaiquan opened this issue · comments

使用Http client请求内网接口,报错400 :

Your browser sent a request that this server could not understand.
Reason: You're speaking plain HTTP to an SSL-enabled server port.
Instead use the HTTPS scheme to access this URL, please.

我的使用方式:
std::string url = "https://192.168.2.3/aaaaaa";
http::web_request req2 = http::make_request(url);
req2.method(http::verb::get);
auto rep2 = asio2::http_client::execute(req2);

以上请求,使用curl或者postman是可以请求到内容的。

commented

改为 asio2::https_client::execute(req2); 即可

asio2::http_client::execute(req2); 只能处理http请求,不能处理https请求。

commented

另:你上面的代码有点重复,直接 auto rep2 = asio2::https_client::execute("https://192.168.2.3/aaaaaa");即可,支持直接传入url字符串

改为 asio2::https_client::execute(req2); 即可

asio2::http_client::execute(req2); 只能处理http请求,不能处理https请求。

忘记看sll的demo了,抱歉

另:你上面的代码有点重复,直接 auto rep2 = asio2::https_client::execute("https://192.168.2.3/aaaaaa");即可,支持直接传入url字符串;%E5%8D%B3%E5%8F%AF%EF%BC%8C%E6%94%AF%E6%8C%81%E7%9B%B4%E6%8E%A5%E4%BC%A0%E5%85%A5url%E5%AD%97%E7%AC%A6%E4%B8%B2)

嗯,我知道,我是简化了我写的代码,我这边还有其他的操作,需要加入一些请求头,只是未展示