简体   繁体   English

C套接字,代理GET请求返回404

[英]C sockets, proxy GET requests returning as 404

I'm creating a simple proxy server and I've run into an issue with getting responses back from a website. 我正在创建一个简单的代理服务器,我遇到了从网站获取响应的问题。

I've set up my server to accept connections on a specified port that gets connected to through the browser proxy config. 我已将服务器设置为接受通过浏览器代理配置连接到的指定端口上的连接。 The server is able to receive the request, connect to the specified website, send the request, and receive a reply. 服务器能够接收请求,连接到指定的网站,发送请求,并收到回复。

I'm forwarding the request from the browser to the website without modification, but the replies I receive are always 404 errors. 我正在将请求从浏览器转发到网站而不做任何修改,但我收到的回复总是404错误。

This is the request I'm fowarding to the website, there is a \\r\\n after every line and \\r\\n\\r\\n after the final line. 这是我向网站发送的请求,每行后都有一个\\ r \\ n,最后一行后面有\\ r \\ n \\ r \\ n。

GET http://www.mywebpage.com/ HTTP/1.1
Host: www.mywebpage.com
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:66.0) Gecko/20100101 Firefox/66.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: __utma=1.35811746.1525489860.1537250282.1539467023.3; __utmz=1.1537250282.2.2.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided); _fbp=fb.1.1553849756364.1600689742
Upgrade-Insecure-Requests: 1

My send receive code looks like this. 我的发送接收代码如下所示。

sendError  = send(serverSock, requestString , strlen(requestString) , 0 );  
returnedSize = recv(serverSock, buffer, sizeof(buffer), 0);

I'm forwarding the request from the browser to the website without modification ... 我正在将请求从浏览器转发到网站而不做任何修改......

 GET http://www.mywebpage.com/ HTTP/1.1 

The absolute URL you use in your request target should only be used for proxies. 您在请求目标中使用的绝对URL应仅用于代理。 Normal servers expect the origin form , ie only the path and optional query but not the full URL. 普通服务器期望原始形式 ,即只有路径和可选查询,而不是完整的URL。 Method, host and port should thus be stripped: 因此应剥离方法,主机和端口:

 GET / HTTP/1.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM