简体   繁体   English

显示使用C ++发送到我的服务器的HTTP请求

[英]Display HTTP Request sent to my server using c++

I am currently learning about the internet. 我目前正在学习互联网。 I am trying to set up a simple proxy server that just forwards a request from the server side to its client side. 我正在尝试建立一个简单的代理服务器,该代理服务器仅将请求从服务器端转发到其客户端。 Im currently following this tutorial. 我目前正在关注教程。 This is how far I have gotten: 这是我走了多远:

#define MYPORT "3490"  // the port users will be connecting to
#define BACKLOG 10     // how many pending connections queue will hold

int main(int argc, const char* argv[]) {
    struct addrinfo hints;
    struct addrinfo *res;
    int sockIn;
    int sockOut;

    memset(&hints, 0, sizeof hints); // make sure its empty
    hints.ai_family = AF_UNSPEC;     // use IPv4 or IPv6, whichever
    hints.ai_socktype = SOCK_STREAM; // what kind of socket
    hints.ai_flags = AI_PASSIVE;     // fill in my IP for me

    //listens on the hosts ip address:
    getaddrinfo(NULL, MYPORT, &hints, &res);

    // make a socket, bind it, and listen on it:
    sockIn = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
    bind(sockIn, res->ai_addr, res->ai_addrlen);
    listen(sockIn, BACKLOG);

    freeaddrinfo(res); // free the linked-list

        struct sockaddr_storage their_addr;
        socklen_t addr_size;
        char buf[512];

        while(1) {
            addr_size = sizeof their_addr;
            struct sockaddr *addr = (struct sockaddr *)&their_addr;
            sockOut = accept(sockIn, addr, &addr_size);
            recv(sockOut, buf, sizeof buf, 0);
            for (auto ch : buf) {
                cout << ch;
            }
            close(sockOut);
        }
}

Right now im just displaying "hi" on every page I visit. 现在,我只是在我访问的每个页面上显示“ hi”。 Before I implement the client side of the proxy id like to instead display the HTTP Get Request that my browser sends to the server side of the proxy. 在实现代理ID的客户端之前,我想显示我的浏览器发送到代理服务器端的HTTP Get Request。 My issue is that I dont know how to retrieve it. 我的问题是我不知道如何检索它。 The guide I'm using is not adressering this. 我正在使用的指南没有解决这个问题。

Edit: I added a recv call that is suppose to read everything from the socket in to a buffer. 编辑:我添加了一个recv调用,该调用应该读取从套接字到缓冲区的所有内容。 Unfortunately it does not cout anything 不幸的是它什么都没有

download and install wireshark (packet sniffer), or else Fiddler Fiddler (HTTP proxy). 下载并安装wireshark (数据包嗅探器),或安装Fiddler Fiddler (HTTP代理)。 You will easily be able to inspect HTTP traffic. 您将能够轻松检查HTTP流量。 I recommend you start with fiddler. 我建议您从提琴手入手。 Install on computer where your browser is located. 在浏览器所在的计算机上安装。

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

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