473,739 Members | 6,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems with HttpWebRequest

I have a very wired problem requesting one specific url from within my
application.

I have struggeled with this for 5 hours now, and searched google withour any
luck, so i hope that someone are able to help me.

Here is the code that i am using:

Dim url As String = "MyIP"
Dim httpRequest As HttpWebRequest = CType(WebReques t.Create(url),
HttpWebRequest)
Dim httpResponse As HttpWebResponse = CType(httpReque st.GetResponse,
HttpWebResponse )

The erro that i get is the following:

"The underlying connection was closed: An unexpected error occurred on a
receive."

Then i downloaded HTTP Analyzer to see what was going on behind the scenes.

When requesting the url from within IE, the content is returned to the
browser windows without any problems, but when the request is made using a
HttpWebRequest strange things happen.

When i monitor what i happening in HTTP Analyser is see that the request is
made from my asp.net program, and the content and a status 200 is returned,
BUT about 500 miliseconds later another request is made to the resource (i
can see that in the monitor program) and this time no content is returned.
This is probabaly why the the framework see this as a malformed response, and
i get the error above.

I have tested the code with 10-15 other addresses with success. The content
is returned, and the resoruce is only requested 1 time. Has anyone seen this
before ?

What is a little bit special about the resource that i request is that the
content is returned with no header info at all, only raw text, but why should
this mean that the resource is accessed two times, when i only call
httpRequest.Get Response one time.

The resource that i access is a simple url hosted on a Apace server which
retuns a text string with no header info at all.

I hope that someone can help me on this, as i think i have tested for
everything.

thanks,
Oliver
Nov 19 '05 #1
6 1968
Does the initial request cause a redirect to a default page?
You might want to set AllowAutoRedire ct to false and see what happens.
I know you said the server does not return a header, but a redirect
would cause 2 requests fromt the client.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sun, 2 Oct 2005 09:24:02 -0700, Oliver
<Ol****@discuss ions.microsoft. com> wrote:
I have a very wired problem requesting one specific url from within my
application.

I have struggeled with this for 5 hours now, and searched google withour any
luck, so i hope that someone are able to help me.

Here is the code that i am using:

Dim url As String = "MyIP"
Dim httpRequest As HttpWebRequest = CType(WebReques t.Create(url),
HttpWebRequest )
Dim httpResponse As HttpWebResponse = CType(httpReque st.GetResponse,
HttpWebRespons e)

The erro that i get is the following:

"The underlying connection was closed: An unexpected error occurred on a
receive."

Then i downloaded HTTP Analyzer to see what was going on behind the scenes.

When requesting the url from within IE, the content is returned to the
browser windows without any problems, but when the request is made using a
HttpWebReque st strange things happen.

When i monitor what i happening in HTTP Analyser is see that the request is
made from my asp.net program, and the content and a status 200 is returned,
BUT about 500 miliseconds later another request is made to the resource (i
can see that in the monitor program) and this time no content is returned.
This is probabaly why the the framework see this as a malformed response, and
i get the error above.

I have tested the code with 10-15 other addresses with success. The content
is returned, and the resoruce is only requested 1 time. Has anyone seen this
before ?

What is a little bit special about the resource that i request is that the
content is returned with no header info at all, only raw text, but why should
this mean that the resource is accessed two times, when i only call
httpRequest.Ge tResponse one time.

The resource that i access is a simple url hosted on a Apace server which
retuns a text string with no header info at all.

I hope that someone can help me on this, as i think i have tested for
everything.

thanks,
Oliver


Nov 19 '05 #2
Thank you for reading my post.

I have tried this and it still requests the url two times, and gives me the
same error.

I have even tried setting header information in my request to the same as
when the url is requested from within my browser, but nothing helps.

I was wondering if the HttpWebResponse does not like responses with no
header info at all, and then requests the resource again ? If this is so,
what are my options then ?

Thanks,
Oliver

"Scott Allen" wrote:
Does the initial request cause a redirect to a default page?
You might want to set AllowAutoRedire ct to false and see what happens.
I know you said the server does not return a header, but a redirect
would cause 2 requests fromt the client.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sun, 2 Oct 2005 09:24:02 -0700, Oliver
<Ol****@discuss ions.microsoft. com> wrote:

Nov 19 '05 #3
I now see that the url returns a HTTP/1.0 200 Simple Response, where as other
urls that i have tried with the HttpWebRequest returns a HTTP/1.1 200 OK
response. Could this 'Simple Response' be the problem ?

"Scott Allen" wrote:
Does the initial request cause a redirect to a default page?
You might want to set AllowAutoRedire ct to false and see what happens.
I know you said the server does not return a header, but a redirect
would cause 2 requests fromt the client.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sun, 2 Oct 2005 09:24:02 -0700, Oliver
<Ol****@discuss ions.microsoft. com> wrote:
I have a very wired problem requesting one specific url from within my
application.

I have struggeled with this for 5 hours now, and searched google withour any
luck, so i hope that someone are able to help me.

Here is the code that i am using:

Dim url As String = "MyIP"
Dim httpRequest As HttpWebRequest = CType(WebReques t.Create(url),
HttpWebRequest )
Dim httpResponse As HttpWebResponse = CType(httpReque st.GetResponse,
HttpWebRespons e)

The erro that i get is the following:

"The underlying connection was closed: An unexpected error occurred on a
receive."

Then i downloaded HTTP Analyzer to see what was going on behind the scenes.

When requesting the url from within IE, the content is returned to the
browser windows without any problems, but when the request is made using a
HttpWebReque st strange things happen.

When i monitor what i happening in HTTP Analyser is see that the request is
made from my asp.net program, and the content and a status 200 is returned,
BUT about 500 miliseconds later another request is made to the resource (i
can see that in the monitor program) and this time no content is returned.
This is probabaly why the the framework see this as a malformed response, and
i get the error above.

I have tested the code with 10-15 other addresses with success. The content
is returned, and the resoruce is only requested 1 time. Has anyone seen this
before ?

What is a little bit special about the resource that i request is that the
content is returned with no header info at all, only raw text, but why should
this mean that the resource is accessed two times, when i only call
httpRequest.Ge tResponse one time.

The resource that i access is a simple url hosted on a Apace server which
retuns a text string with no header info at all.

I hope that someone can help me on this, as i think i have tested for
everything.

thanks,
Oliver


Nov 19 '05 #4
I have tried forcing the http protocol to Version 1.0 with
httpRequest.Pro tocolVersion = HttpVersion.Ver sion10

This gives the same error, and the url is still reqested 2 times.

"Oliver" wrote:
I now see that the url returns a HTTP/1.0 200 Simple Response, where as other
urls that i have tried with the HttpWebRequest returns a HTTP/1.1 200 OK
response. Could this 'Simple Response' be the problem ?

"Scott Allen" wrote:
Does the initial request cause a redirect to a default page?
You might want to set AllowAutoRedire ct to false and see what happens.
I know you said the server does not return a header, but a redirect
would cause 2 requests fromt the client.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sun, 2 Oct 2005 09:24:02 -0700, Oliver
<Ol****@discuss ions.microsoft. com> wrote:
I have a very wired problem requesting one specific url from within my
application.

I have struggeled with this for 5 hours now, and searched google withour any
luck, so i hope that someone are able to help me.

Here is the code that i am using:

Dim url As String = "MyIP"
Dim httpRequest As HttpWebRequest = CType(WebReques t.Create(url),
HttpWebRequest )
Dim httpResponse As HttpWebResponse = CType(httpReque st.GetResponse,
HttpWebRespons e)

The erro that i get is the following:

"The underlying connection was closed: An unexpected error occurred on a
receive."

Then i downloaded HTTP Analyzer to see what was going on behind the scenes.

When requesting the url from within IE, the content is returned to the
browser windows without any problems, but when the request is made using a
HttpWebReque st strange things happen.

When i monitor what i happening in HTTP Analyser is see that the request is
made from my asp.net program, and the content and a status 200 is returned,
BUT about 500 miliseconds later another request is made to the resource (i
can see that in the monitor program) and this time no content is returned.
This is probabaly why the the framework see this as a malformed response, and
i get the error above.

I have tested the code with 10-15 other addresses with success. The content
is returned, and the resoruce is only requested 1 time. Has anyone seen this
before ?

What is a little bit special about the resource that i request is that the
content is returned with no header info at all, only raw text, but why should
this mean that the resource is accessed two times, when i only call
httpRequest.Ge tResponse one time.

The resource that i access is a simple url hosted on a Apace server which
retuns a text string with no header info at all.

I hope that someone can help me on this, as i think i have tested for
everything.

thanks,
Oliver


Nov 19 '05 #5
I have neverheard of a "200 Simple" response, unless you meant a "simple"
200 response. In either case, it means OK. It certainly does sound offhand
like a redirect is occurring, but if you have set AutoRedirect to false,
that should not happen. One thing you can do is to log the headers and the
Response Stream (as a string) to get more detailed information about what is
going on.

I am also working on a project using HttpWebRequest and HttpWebResponse . One
of the URLs I had trouble with was looking for a cookie that would have been
set with the previous Response. I discovered that the Response.Cookie s
collection is not auto-populated, and had to write my own code to get the
cookie from the previous Response, and insert it into the Request.Cookies
collection.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Big things are made up of
lots of little things.

"Oliver" <Ol****@discuss ions.microsoft. com> wrote in message
news:FF******** *************** ***********@mic rosoft.com...
I now see that the url returns a HTTP/1.0 200 Simple Response, where as
other
urls that i have tried with the HttpWebRequest returns a HTTP/1.1 200 OK
response. Could this 'Simple Response' be the problem ?

"Scott Allen" wrote:
Does the initial request cause a redirect to a default page?
You might want to set AllowAutoRedire ct to false and see what happens.
I know you said the server does not return a header, but a redirect
would cause 2 requests fromt the client.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sun, 2 Oct 2005 09:24:02 -0700, Oliver
<Ol****@discuss ions.microsoft. com> wrote:
>I have a very wired problem requesting one specific url from within my
>application.
>
>I have struggeled with this for 5 hours now, and searched google withour
>any
>luck, so i hope that someone are able to help me.
>
>Here is the code that i am using:
>
>Dim url As String = "MyIP"
>Dim httpRequest As HttpWebRequest = CType(WebReques t.Create(url),
>HttpWebRequest )
>Dim httpResponse As HttpWebResponse = CType(httpReque st.GetResponse,
>HttpWebRespons e)
>
>The erro that i get is the following:
>
>"The underlying connection was closed: An unexpected error occurred on a
>receive."
>
>Then i downloaded HTTP Analyzer to see what was going on behind the
>scenes.
>
>When requesting the url from within IE, the content is returned to the
>browser windows without any problems, but when the request is made using
>a
>HttpWebReque st strange things happen.
>
>When i monitor what i happening in HTTP Analyser is see that the request
>is
>made from my asp.net program, and the content and a status 200 is
>returned,
>BUT about 500 miliseconds later another request is made to the resource
>(i
>can see that in the monitor program) and this time no content is
>returned.
>This is probabaly why the the framework see this as a malformed
>response, and
>i get the error above.
>
>I have tested the code with 10-15 other addresses with success. The
>content
>is returned, and the resoruce is only requested 1 time. Has anyone seen
>this
>before ?
>
>What is a little bit special about the resource that i request is that
>the
>content is returned with no header info at all, only raw text, but why
>should
>this mean that the resource is accessed two times, when i only call
>httpRequest.Ge tResponse one time.
>
>The resource that i access is a simple url hosted on a Apace server
>which
>retuns a text string with no header info at all.
>
>I hope that someone can help me on this, as i think i have tested for
>everything.
>
>thanks,
>Oliver


Nov 19 '05 #6
I gave up using the HttpWebRequest class and ordered PowerTCP Sockets for
..NET from Dart, and now i works as expected.

"Kevin Spencer" wrote:
I have neverheard of a "200 Simple" response, unless you meant a "simple"
200 response. In either case, it means OK. It certainly does sound offhand
like a redirect is occurring, but if you have set AutoRedirect to false,
that should not happen. One thing you can do is to log the headers and the
Response Stream (as a string) to get more detailed information about what is
going on.

I am also working on a project using HttpWebRequest and HttpWebResponse . One
of the URLs I had trouble with was looking for a cookie that would have been
set with the previous Response. I discovered that the Response.Cookie s
collection is not auto-populated, and had to write my own code to get the
cookie from the previous Response, and insert it into the Request.Cookies
collection.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Big things are made up of
lots of little things.

"Oliver" <Ol****@discuss ions.microsoft. com> wrote in message
news:FF******** *************** ***********@mic rosoft.com...
I now see that the url returns a HTTP/1.0 200 Simple Response, where as
other
urls that i have tried with the HttpWebRequest returns a HTTP/1.1 200 OK
response. Could this 'Simple Response' be the problem ?

"Scott Allen" wrote:
Does the initial request cause a redirect to a default page?
You might want to set AllowAutoRedire ct to false and see what happens.
I know you said the server does not return a header, but a redirect
would cause 2 requests fromt the client.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sun, 2 Oct 2005 09:24:02 -0700, Oliver
<Ol****@discuss ions.microsoft. com> wrote:

>I have a very wired problem requesting one specific url from within my
>application.
>
>I have struggeled with this for 5 hours now, and searched google withour
>any
>luck, so i hope that someone are able to help me.
>
>Here is the code that i am using:
>
>Dim url As String = "MyIP"
>Dim httpRequest As HttpWebRequest = CType(WebReques t.Create(url),
>HttpWebRequest )
>Dim httpResponse As HttpWebResponse = CType(httpReque st.GetResponse,
>HttpWebRespons e)
>
>The erro that i get is the following:
>
>"The underlying connection was closed: An unexpected error occurred on a
>receive."
>
>Then i downloaded HTTP Analyzer to see what was going on behind the
>scenes.
>
>When requesting the url from within IE, the content is returned to the
>browser windows without any problems, but when the request is made using
>a
>HttpWebReque st strange things happen.
>
>When i monitor what i happening in HTTP Analyser is see that the request
>is
>made from my asp.net program, and the content and a status 200 is
>returned,
>BUT about 500 miliseconds later another request is made to the resource
>(i
>can see that in the monitor program) and this time no content is
>returned.
>This is probabaly why the the framework see this as a malformed
>response, and
>i get the error above.
>
>I have tested the code with 10-15 other addresses with success. The
>content
>is returned, and the resoruce is only requested 1 time. Has anyone seen
>this
>before ?
>
>What is a little bit special about the resource that i request is that
>the
>content is returned with no header info at all, only raw text, but why
>should
>this mean that the resource is accessed two times, when i only call
>httpRequest.Ge tResponse one time.
>
>The resource that i access is a simple url hosted on a Apace server
>which
>retuns a text string with no header info at all.
>
>I hope that someone can help me on this, as i think i have tested for
>everything.
>
>thanks,
>Oliver


Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1693
by: Adam Stirk | last post by:
Hi, I am trying to download a image that is generated by PHP using HttpWebRequest, I believe the server uses cookies to generate the image, but I keep getting the error image from the server. Can anyone help? The code I am using is :-
16
12644
by: thomas peter | last post by:
I am building a precache engine... one that request over 100 pages on an remote server to cache them remotely... can i use the HttpWebRequest and WebResponse classes for this? or must i use the MSHTML objects to really load the HTML and request all of the images on site? string lcUrl = http://www.cnn.com; // *** Establish the request
3
1965
by: Sean Chapman | last post by:
ok, heres the problem.. i have an asp.net page that im using to kind of relay information back and forth. So on the Page_Load i make a request to a webservice and return some xml back to the first calling app. now... i wrote a test app to try it out, but i cannot get the proper data from it. It always says the the ContentLength is -1 so my my StreamReader.ReadToEnd throws an exception.. heres the chunk of code in the driver app: ...
3
1957
by: Dales | last post by:
I'm trying to screen scrape for some data, but the response that comes back is the "Browser Detect" page. Is there any way to "impersonate" a browser (IE6.0 for example)?
1
1491
by: GSK | last post by:
This one has me stumped: I am using HttpWebRequest to resolve an external URL (that outputs an XML string). It works fine on my dev machine (W2K), and used to work on my production machine (W2K3). It seems that now, for some reason, the connection cannot be established. The error logged is: The underlying connection was closed: Unable to connect to the remote server." source="System" stack="at...
1
1439
by: mroffey | last post by:
Hi I'm using the code below to post to a web form, but when I run it, i get System.Net.WebException: The operation has timed-out. error Obviously something is wrong, can anyone give me a clue? string url = "http://localhost/testapp/test.asp"; HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); myHttpWebRequest.Credentials = new NetworkCredential("username",
2
3333
by: Tyler | last post by:
I am using httpwebrequest to do a screen scrape. This works great on my development box, but does not on the production box. Here is the code. Dim webRequest As HttpWebRequest = CType(webRequest.Create(LOGIN_URL), HttpWebRequest) webRequest.Proxy = System.Net.GlobalProxySelection.GetEmptyWebProxy webRequest.KeepAlive = False
1
3429
by: Sam | last post by:
Hi All, I'm trying to write a simple multi-threaded windows service application using ThreadPool and I'm running into the same problem as described by MS article: http://support.microsoft.com/default.aspx?scid=kb;en-us;815637#appliesto . The sample code down here is from the above article. Would anyone give me some directions how to overcome the deadlock issue with thread pull. The exception that I get after all threads in the...
3
4881
by: matadon | last post by:
Hi, I am writing a C# app. I have a finite (~50) set of URLs that I am continuously polling in a circular manner. I would like to do this in a way that can send out each of the requests and get responses as quickly as possible, then do it again. For my last attempt, I tried implementing a circular queue of precreated HttpWebRequest objects, then creating a HttpWebResponse, StreamReader, and Stream and disposing of them after usage. My...
0
8969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9479
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9266
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9209
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8215
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6754
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4826
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.