Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

HttpWebRequest returns only strange characters in the response

$
0
0

Hello,

I am trying to get the HTML from a page. When I use the below code I receive 170 KB of characters that looks like this:

"ɓdg   K  <? b"c~ C aH?aH 4"Or]"

I wonder if there is any wrong with the: Header, ContentType or Useragent etc?

See complete code:

                            String requestURL = "http://www.booking.com/searchresults.en-gb.html?aid=356982;label=gog235jc-region-XX-gr-poros-unspec-fr-com-L%3Aen-O%3Aunk-B%3Aunk-N%3Ayes-S%3Abo-U%3Asalo;sid=f2bb069850b01b677aee4d5e626cdccb;dcid=4;checkin_monthday=16;checkin_year_month=2016-01;checkout_monthday=17;checkout_year_month=2016-01;class_interval=1;csflt=%7B%7D;dtdisc=0;group_adults=2;group_children=0;hlrd=0;hyb_red=0;inac=0;label_click=undef;nha_red=0;no_rooms=1;redirected_from_city=0;redirected_from_landmark=0;redirected_from_region=0;region=3719;review_score_group=empty;room1=A%2CA;sb_price_type=total;score_min=0;si=ai%2Cco%2Cci%2Cre%2Cdi;src=searchresults;ss=Poros+Island;ss_all=0;ssafas=1;ssb=empty;sshis=0;ssne=Poros+Island;ssne_untouched=Poros+Island;track_sas=1;rows=15;offset=0";

                            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestURL);
                            request.Method = "GET";
                            request.Headers.Add("Accept-Encoding: gzip,deflate,sdch");
                            request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
                            request.ContentType = "text/html; charset=utf-8";



                            String getHTML = String.Empty;
                            try
                            {
                                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                                {
                                    Stream dataStream = response.GetResponseStream();
                                    StreamReader reader = new StreamReader(dataStream);
                                    getHTML = reader.ReadToEnd();
                                    reader.Close();
                                    dataStream.Close();
                                }
                            }
                            catch (Exception ex) { MessageBox.Show(ex.ToString()); }


                            //Create file
                            StreamWriter writer = null; FileStream fs = null;
                            fs = new FileStream("C:/HTML.txt", FileMode.Create, FileAccess.Write, FileShare.ReadWrite); writer = new StreamWriter(fs);
                            writer.WriteLine(getHTML);
                            writer.Close(); fs.Close();


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>