Problems with WebRequest

Last post 05-07-2007 2:34 AM by Rex Lin - MSFT. 1 replies.

Sort Posts:

  • Problems with WebRequest

    05-04-2007, 11:46 AM
    • Member
      60 point Member
    • Xavieret
    • Member since 05-18-2006, 8:22 PM
    • Spain
    • Posts 15

    Hi everybody,

     

    I have a web page where i want to get the html source of another web page. This web page is: http://s1.viastreaming.net:8000/7.html, you can see that i only want to know the name of a song.

     I try to put in my page these lines to get the html source:

     

    protected string ObtenerWeb()
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://s1.viastreaming.net:8000/7.html");
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream resStream = response.GetResponseStream();
            StreamReader StreamRead = new StreamReader(resStream);
            string Contenido = StreamRead.ReadToEnd().ToString();
    
            return Contenido;
        }

     
    And i have to add these lines in my web.config, because when they aren't in my web.config the server returns me this error: "The server committed a protocol violation. Section=ResponseStatusLine". I solve this problem adding these lines:

     

    <system.net>
    		<settings>
    			<httpWebRequest useUnsafeHeaderParsing="true" />
    		</settings>
    	</system.net>

      

    Ok, now I can get the response without errors, but i only can read bad characters. For example: "(In7%7GSOZ*x:2X_O\0_`߰X8E/\a՟籬\0($0E'\0՛jeB=JXzIr-!ZVOЮ)znbJ.]Xޡ7H|.f鳼Aq"

     I think that the problem is with the codification, but i don't know how i can solve it, Do you know?
     

     

    for a better development...
  • Re: Problems with WebRequest

    05-07-2007, 2:34 AM
    Answer

        HI, Xavieret;

    I have tested you code in my VS and it works as a charm. I believe it is some problem in codification and try to use this following code and let me know the result.  

     

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://s1.viastreaming.net:8000/7.html");
           
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream resStream = response.GetResponseStream();
            StreamReader StreamRead = new StreamReader(resStream, Encoding.ASCII);        
            string Contenido =HttpUtility.HtmlDecode( StreamRead.ReadToEnd().ToString());

            return Contenido;

    I hope the above information will be helpful. If you have any issues or concerns, please let me know. It's my pleasure to be of assistance

    Best Regards,
    __________________________________________________
    Sincerely,
    Rex Lin
    Microsoft Online Community Support

    If there is any question or the issue is not resolved, please feel free to mark the thread as not resolved
Page 1 of 1 (2 items)