c# - The correct way to retrieve data from a HttpWebRespose Stream then add text -
I'm trying to retrieve a web page, by sending some text at the top of the page, sending the string. Here's an example structure of what I'm trying to do, is it the right method or is I a big number somewhere-no one?
HTTP WebBurvey Request = (HTTP WebBarb) WebRequest.Create ("http://www.example.com"); Var responce = (HttpWebResponse) Request. GetResponse (); Var responseflow = responce.getResponseStream (); Streamer reader = new streamreader (responses); String feedback string = reader. Readout (); Stringbilder sb = new stringbilder (response string); Var Index = SB ToString (). Indexoff ("& lt; body"; String Communications, Invariant Culture Ignore Case) + "Body & gt; Body & gt;" Length; Sb.Insert (index, "lots of text goes here."); Console.WriteLine (sb.ToString ());
Do you have any specific reasons for using HTTP WebBrm / Response? You can optionally use the WebClient class to get the same result:
WebClient web_client = new WebClient (); Byte [] results = web_client.DownloadData ("http: // blah ..."); String html = System.Text.Encoding.Default.GetString (Results); Html.IndexOf ("& lt; body & gt;") ...
Just like a little less code
Comments
Post a Comment