Archived Forum Post

Index of archived forum posts

Question:

How to make correct GET/POST with Host resolving proxy?

May 09 '13 at 20:24

Hey.

My Socks proxy resolves hostnames from "www.google.com.foo.bar" to "www.google.com". What do I have to do that the Google server gets the right host value "www.google.com" and not "www.google.com.foo.bar"?

            Uri uri = new Uri("http://www.google.com/search?q=chilikat");
            string googleHost= "www.google.com";
            string googleHostForResolvingSocksProxy= "www.google.com.foo.bar";

            Chilkat.HttpRequest req = new Chilkat.HttpRequest();
            req.Path = uri.PathAndQuery;
            req.AddHeader("Host", googleHost);

            if(postData!=null)
            {
                    req.HttpVerb = WebRequestMethods.Http.Post;
                    req.ContentType="application/x-www-form-urlencoded;";
                    req.AddParam("name","value");
            }

            Chilkat.HttpResponse resp = http.SynchronousRequest(googleHostForResolvingSocksProxy, 80, false, req);

I think GET is working well, but I can not check it yet (correct host and request headers). POST is definitly not working. I get a "Not Found" error. Probably because of wrong Host header.

What do I have to change? Could you help me please.

BlackMatrix


Answer

You can see the exact HTTP request sent by setting the http.SessionLogFilename property to the path of a file that the Chilkat.Http object will create/append when sending requests. Once you see what is actually sent, it might provide the clue as to what is wrong..


Answer

Ah, nice feature. Redirection was the problem. Chilikat is doing a bad request if you get redirected.

It doint the following redirecting GET request:

GET / HTTP/1.1
Accept: */*
Accept-Encoding: gzip
...
User-Agent: Chilkat/1.0.0 (+http://www.chilkatsoft.com/ChilkatHttpUA.asp)
Host: www.google.com
Connection: Keep-Alive

I think I have to define the order and the values of the Chilikat.Http object, not just for HttpRequest. Maybe then Redirection is working with the same headers as the HttpRequest object.

Question: I'm using Send- and SaveCookies from Chilikat.Http. How could I change the order of the headers? Cookie header must be before Connection: Keep-Alive not at the end like the following:

POST / HTTP/1.1
Host: www.google.com
Connection: Keep-Alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 10
Cookie: name=value