0

I have a proxy server setup for my browser (Firefox 21, IE10). The strange thing is whenever there is & # 3 9 ; (please ignore the spaces) in the request URL, the browser will not sent it and anything after that.

Initially I thought this is a problem with the proxy server, so I wrote a simple socket server and try to see what the browser sends (see below). When I debug through the code the it proves that the browser indeed is NOT sending ' and everything after that. Anyone has ever seen this before? Why is this happening?

    nFd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
    if(nFd < 0) break;

    sockaddr_in addr = {0};
    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = htonl(INADDR_ANY);
    addr.sin_port = htons(7995);
    int nAddrLen = sizeof(addr);

    if(0 != ::bind(nFd, (const sockaddr*)&addr, nAddrLen))
        break;

    if(0 != listen(nFd, 64))
        break;

    nClientFd = accept(nFd, (sockaddr*)&addr, &nAddrLen);
    if(nClientFd < 0) break;


    char buf[16384] = {0};
    int nBytesRead = recv(nClientFd, buf, 16384, 0);
    if(nBytesRead <= 0) break;

    cout << buf << endl;

Here is the request that I type to the address bar (ignore the spaces in & # 3 9 ;, it's only there so that it will show up on this page:

www.test.com/go& # 3 9 ; tome

Here is the request that I received through the socket:

GET http://www.test.com/go& HTTP/1.1
Host: www.test.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.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

Note the request line. I really cannot explain this...

4

1 回答 1

0

#字符在 HTTP/HTTPS URL 中保留,并标记 URLfragment组件的开始。HTTP/HTTPS URL 的这一部分永远不会发送到服务器。如果您希望将 # 字符和后续信息发送到服务器,则 # 必须 URL 编码为 %23。

于 2013-06-18T21:35:06.797 回答