2

I'm trying to view captcha from a site, but I screw something, because it is incorrect when I submit the answer, though I get the session and everything, so I decided to do it request by request, exactly the way they appear in fiddler, but it is https, and I can't find a tutorial, or explanation or anything about https requests in C#, for example, the first request is:

CONNECT passport.abv.bg:443 HTTP/1.1 User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:29.0) Gecko/20100101 Firefox/29.0 Connection: keep-alive Connection: keep-alive Host: passport.abv.bg

so I try to do it like that:

HttpWebRequest req0 = (HttpWebRequest)WebRequest.Create("https://passport.abv.bg:443/");
        req0.Method = "CONNECT";
        req0.KeepAlive = true;
        req0.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:29.0) Gecko/20100101 Firefox/29.0";
        req0.Host = "passport.abv.bg";

        HttpWebResponse resp0 = (HttpWebResponse)req0.GetResponse();
        StreamReader Reader0 = new StreamReader(resp0.GetResponseStream());
        string thePage0 = Reader0.ReadToEnd();
        Reader0.Close();

and of course it won't work, I can't even see the result, as it's not string, and the application freezes.. Can you give me some info please, I really can't find any explanation how to use https requests in C#

Andrew
  • 14,325
  • 4
  • 43
  • 64
  • maybe the server(passport.abv.bg:443) does not reply for CONNECT message. There is nothing to read. `Reader0.ReadToEnd();` – Abdullah May 18 '14 at 14:08
  • I don't think this is the case, since in fiddler I get response. It must be wrong, as I really don't know what I'm doing, I coded the request hoping it will at least throw some error so I can start from somewhere, but no.. – user3192953 May 18 '14 at 15:20
  • What happens if: 1. You don't set `req0.Method` or `req0.Host` explicitly, and 2. You check the value of `resp0.StatusCode` before or instead of attempting to read the response stream? – Andrew Sep 01 '14 at 19:10
  • .NET will handle HTTPS automatically for you, you can use the same code for HTTP, except the Uri with https. Can you post a link to where the captcha appear? – yume_chan Sep 01 '14 at 21:01
  • As Simon said, httpwebrequest automatically handles this. just create it with correct url: HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://passport.abv.bg") – feroze Feb 27 '15 at 01:12

0 Answers0