473,394 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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(WebRequest.Create(url),
HttpWebRequest)
Dim httpResponse As HttpWebResponse = CType(httpRequest.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.GetResponse 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 1949
Does the initial request cause a redirect to a default page?
You might want to set AllowAutoRedirect 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****@discussions.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(WebRequest.Create(url),
HttpWebRequest)
Dim httpResponse As HttpWebResponse = CType(httpRequest.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.GetResponse 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 AllowAutoRedirect 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****@discussions.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 AllowAutoRedirect 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****@discussions.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(WebRequest.Create(url),
HttpWebRequest)
Dim httpResponse As HttpWebResponse = CType(httpRequest.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.GetResponse 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.ProtocolVersion = HttpVersion.Version10

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 AllowAutoRedirect 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****@discussions.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(WebRequest.Create(url),
HttpWebRequest)
Dim httpResponse As HttpWebResponse = CType(httpRequest.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.GetResponse 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.Cookies
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****@discussions.microsoft.com> wrote in message
news:FF**********************************@microsof t.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 AllowAutoRedirect 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****@discussions.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(WebRequest.Create(url),
>HttpWebRequest)
>Dim httpResponse As HttpWebResponse = CType(httpRequest.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.GetResponse 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.Cookies
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****@discussions.microsoft.com> wrote in message
news:FF**********************************@microsof t.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 AllowAutoRedirect 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****@discussions.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(WebRequest.Create(url),
>HttpWebRequest)
>Dim httpResponse As HttpWebResponse = CType(httpRequest.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.GetResponse 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
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. ...
16
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...
3
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...
3
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
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...
1
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?...
2
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 =...
1
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:...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.