Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I try to fetch the content of this URL
http://www.yellowpages.com.au/qld/gatton/a-12000029-listing.html[^]
C#
using System.Net;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(link);
request.AllowAutoRedirect = true;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();
StreamReader objSR;
objSR = new StreamReader(resStream, System.Text.Encoding.GetEncoding("utf-8"));
string sResponse = objSR.ReadToEnd();

I don't get any response from the server. Please help me find out why this happens.

Thanks in advance!
Posted
Updated 18-Feb-11 1:44am
v4
Comments
Nithin Sundar 18-Feb-11 6:49am    
Added code block in edit.
Manfred Rudolf Bihy 18-Feb-11 11:10am    
You said in youf comment: "'dataStream.Length' threw an exception of type 'System.NotSupportedException'"

which is quite amusing as I can't see any dataStream.Length in your code. So please give us the full details of the error you are receiving and most of all: Why wasn't this important information part of your question first of all.

So give us these info bits:- Error message- Stacktrace

- place in your code where the error/exception occurred

Without that information there will be no help.

Are you saying that sResponse is equal to String.Empty? Inspect the HttpWebResponse instance response to see what headers the server returned. Or are you trying to tell us that the request.GetResponse() call doesn't return?

Inspecting the headers is easy via the property HttpWebResponse.Headers.

Cheers!
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 18-Feb-11 10:55am    
OP commented

when i use depug i see this exception on the response length \

'dataStream.Length' threw an exception of type 'System.NotSupportedException'
Sergey Alexandrovich Kryukov 18-Feb-11 10:59am    
Manfred, my "5" is upfront payment, you'll help this guy, I know.
Have fun :-) hi-hi...
--SA
Hi

try this and you might get the result.

VB
Public Function GetResponce(ByVal url As String) As String
        Dim strhtml As String = ""
        Dim http As New Chilkat.Http()
        Dim unlocked As Boolean = http.UnlockComponent("code to unlock the HTTP component")
        If Not unlocked Then
            MessageBox.Show("Failed to unlock HTTP component")
            Return Nothing
        End If
        ' Do an HTTP GET to get the HTML source of a web page.
        ' The QuickGetStr and QuickGet methods automatically handle SSL.
        Dim html As String = http.QuickGetStr(url)
        If html Is Nothing Then
            MessageBox.Show(http.LastErrorText)
        Else
            strhtml = html
        End If
        Return strhtml
    End Function
 
Share this answer
 
Comments
Manfred Rudolf Bihy 18-Feb-11 7:55am    
First this code is V... V... VB and not C#. Secondly you are using some obscure class library that contains the type Chilkat. This is not an answer to OP's question. Please edit you answer into something that resembles an answer to OP's question.
Sergey Alexandrovich Kryukov 18-Feb-11 10:55am    
Manfred, I'm not much mistaken, I can understand your stuttering :-)
--SA
Manfred Rudolf Bihy 18-Feb-11 11:04am    
Sh.. sh.. sure you did! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900