473,473 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

HttpWebRequest/HttpWebResponse problem...


Hi everyone,

We are using HttpWebRequest to create a request to a URI, which requires us
to login first. In order to process all the transactions, first we have to
login and get the cookie value in a variable and make the request again with
that cookie as a header value (Digest Authentication).
But, the problem we are facing is: That the HttpWebRequest is getting two
responses simultaneously, which means that the code should wait after the
first response is received, throw an error, so that we can take the cookie
value and make a request again, but, its not working that way, the request
objects gets two values as response (we watched it through Packet Sniffer).
Packet Sniffer shows two responses received, the first one is 401 and the
second one is the successful one. Ideally it should break the code after
401, but it doesn't, any clue as to why it doesn't waits after the first
response ? Could there be any problem with the server ? Or anything wrong
with our code (mentioned below).

The server (ASPX URL) we are trying to connect has .NET Framework 1.1 and
Http/1.1

Following is the code we are using to get the response object from the
request:

HttpWebRequest request = null; // Holds the instance of Http request

try

{
request = (HttpWebRequest)WebRequest.Create(new Uri(uri));

if(ParameterTable.ContainsKey("UserName"))
{
if(ParameterTable.Contains("Password"))
{
request.Credentials = new NetworkCredential
((String)ParameterTable["UserName"],(String)ParameterTable["Password"]);
}
}

if(ParameterTable.ContainsKey("Cookie"))
{
if (!requestParameters.ContainsKey("Cookie"))
{
requestParameters.Add("Cookie",ParameterTable["Cookie"]);
}
}

if(ParameterTable.ContainsKey("Authorization"))
{
if (!requestParameters.ContainsKey("Authorization"))
{

requestParameters.Add("Authorization",ParameterTab le["Authorization"]);
}
}
if(UserAgent!=null && UserAgent!="")
{
request.UserAgent = UserAgent;
}
else
{
request.UserAgent = "RETSExpress/1.0";
}

HttpWebResponse wr = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(wr.GetResponseStream());
string abc = sr.ReadToEnd();
return (HttpWebResponse)request.GetResponse();

}

catch.... part...

In the above code either the value of abc should be both the responses, or
it should break after 401 and get in to the catch part. This code works
smooth with most of the URIs, its only one URI which is giving problem.

Responses Received:
----------------------------------------------------------------------------
----------------------------------------------------------------------------
--------------------------------------------------------
HTTP/1.1 401 Unauthorized
Server: Microsoft-IIS/5.0
Date: Wed, 02 Jun 2004 09:20:18 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
WWW-Authenticate: Digest qop="auth", realm="Se****@metrolist.com",
nonce="40f1e303f5389bff1864edee6c308795",
opaque="c05d7e6b44c97bf3d38ccee27f34b10b"
RETS-Version: RETS/1.5
Local Time: 6/2/2004 3:20:17 AM
Request client: 203.200.29.119
Error: NO_NONCE
Set-Cookie: ASP.NET_SessionId=zm0hcr55iia33jbtx4czxibj; path=/
Set-Cookie: RETS-Session-ID=RETSSESS-252f7f30-d2ab-4944-847b-ed8f207c2628;
path=/
Cache-Control: private
Content-Type: text/xml
----------------------------------------------------------------------------
----------------------------------------------------------------------------
--------------------------------------------------------

Immediately after the above response, the next response it shows in Packet
Sniffer is:

----------------------------------------------------------------------------
----------------------------------------------------------------------------
--------------------------------------------------------
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Wed, 02 Jun 2004 09:20:25 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
WWW-Authenticate: Digest qop="auth", realm="Se****@metrolist.com",
nonce="40f1e303f5389bff1864edee6c308795",
opaque="c05d7e6b44c97bf3d38ccee27f34b10b"
RETS-Version: RETS/1.5
Local Time: 6/2/2004 3:20:24 AM
Request client: 203.200.29.119
Error:
Transfer-Encoding: chunked
Set-Cookie: ASP.NET_SessionId=ho1dj5vsbme0l52q4hzun33f; path=/
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Though it should have returned back to the code after the 401 unauthorized
error as a WebException, which works fine with all the other URIs.

Any help would be highly appreciated. Sorry for a long description, but we
thought it would make sense to put as much info. as possible.

Thanks
Satinder
Jul 21 '05 #1
1 3182
you have to stop multiposting.
-Dino

"Satinderpal Singh" <sa**********@planetasia.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

Hi everyone,

We are using HttpWebRequest to create a request to a URI, which requires us to login first. In order to process all the transactions, first we have to
login and get the cookie value in a variable and make the request again with that cookie as a header value (Digest Authentication).
But, the problem we are facing is: That the HttpWebRequest is getting two
responses simultaneously, which means that the code should wait after the
first response is received, throw an error, so that we can take the cookie
value and make a request again, but, its not working that way, the request
objects gets two values as response (we watched it through Packet Sniffer). Packet Sniffer shows two responses received, the first one is 401 and the
second one is the successful one. Ideally it should break the code after
401, but it doesn't, any clue as to why it doesn't waits after the first
response ? Could there be any problem with the server ? Or anything wrong
with our code (mentioned below).

The server (ASPX URL) we are trying to connect has .NET Framework 1.1 and
Http/1.1

Following is the code we are using to get the response object from the
request:

HttpWebRequest request = null; // Holds the instance of Http request

try

{
request = (HttpWebRequest)WebRequest.Create(new Uri(uri));

if(ParameterTable.ContainsKey("UserName"))
{
if(ParameterTable.Contains("Password"))
{
request.Credentials = new NetworkCredential
((String)ParameterTable["UserName"],(String)ParameterTable["Password"]);
}
}

if(ParameterTable.ContainsKey("Cookie"))
{
if (!requestParameters.ContainsKey("Cookie"))
{
requestParameters.Add("Cookie",ParameterTable["Cookie"]);
}
}

if(ParameterTable.ContainsKey("Authorization"))
{
if (!requestParameters.ContainsKey("Authorization"))
{

requestParameters.Add("Authorization",ParameterTab le["Authorization"]);
}
}
if(UserAgent!=null && UserAgent!="")
{
request.UserAgent = UserAgent;
}
else
{
request.UserAgent = "RETSExpress/1.0";
}

HttpWebResponse wr = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(wr.GetResponseStream());
string abc = sr.ReadToEnd();
return (HttpWebResponse)request.GetResponse();

}

catch.... part...

In the above code either the value of abc should be both the responses, or
it should break after 401 and get in to the catch part. This code works
smooth with most of the URIs, its only one URI which is giving problem.

Responses Received:
-------------------------------------------------------------------------- -- -------------------------------------------------------------------------- -- --------------------------------------------------------
HTTP/1.1 401 Unauthorized
Server: Microsoft-IIS/5.0
Date: Wed, 02 Jun 2004 09:20:18 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
WWW-Authenticate: Digest qop="auth", realm="Se****@metrolist.com",
nonce="40f1e303f5389bff1864edee6c308795",
opaque="c05d7e6b44c97bf3d38ccee27f34b10b"
RETS-Version: RETS/1.5
Local Time: 6/2/2004 3:20:17 AM
Request client: 203.200.29.119
Error: NO_NONCE
Set-Cookie: ASP.NET_SessionId=zm0hcr55iia33jbtx4czxibj; path=/
Set-Cookie: RETS-Session-ID=RETSSESS-252f7f30-d2ab-4944-847b-ed8f207c2628;
path=/
Cache-Control: private
Content-Type: text/xml
-------------------------------------------------------------------------- -- -------------------------------------------------------------------------- -- --------------------------------------------------------

Immediately after the above response, the next response it shows in Packet
Sniffer is:

-------------------------------------------------------------------------- -- -------------------------------------------------------------------------- -- --------------------------------------------------------
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Wed, 02 Jun 2004 09:20:25 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
WWW-Authenticate: Digest qop="auth", realm="Se****@metrolist.com",
nonce="40f1e303f5389bff1864edee6c308795",
opaque="c05d7e6b44c97bf3d38ccee27f34b10b"
RETS-Version: RETS/1.5
Local Time: 6/2/2004 3:20:24 AM
Request client: 203.200.29.119
Error:
Transfer-Encoding: chunked
Set-Cookie: ASP.NET_SessionId=ho1dj5vsbme0l52q4hzun33f; path=/
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Though it should have returned back to the code after the 401 unauthorized
error as a WebException, which works fine with all the other URIs.

Any help would be highly appreciated. Sorry for a long description, but we
thought it would make sense to put as much info. as possible.

Thanks
Satinder

Jul 21 '05 #2

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

Similar topics

0
by: TJO | last post by:
Can someone at MS please reply to this. I am trying to post data so a web form via ssl with the following code. I keep getting this error: "The underlying connection was closed: Could not...
2
by: Kueishiong Tu | last post by:
I have a url, I pass it to Webclient, and I get response without any problem. String* uriString = S"trade7.masterlink.com.tw/futures/QuotePrice.jsp"; String* postData = S""; // Create a new...
1
by: Satinderpal Singh | last post by:
Hi everyone, We are using HttpWebRequest to create a request to a URI, which requires us to login first. In order to process all the transactions, first we have to login and get the cookie value...
2
by: Steve Richter | last post by:
I have a page that uses simple HTTP GET to do an ISBN lookup via Amazon.com. The page works when I run it from //localhost. But I have moved it to my godaddy.com shared hoster site, and I get...
6
by: Oliver | last post by:
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...
16
by: Cheung, Jeffrey Jing-Yen | last post by:
I have a windows form application that generates a request, downloads an image, and waits the user to enter in login info. Unfortunately, this image is dynamic and based on session data. I have...
1
by: Satinderpal Singh | last post by:
Hi everyone, We are using HttpWebRequest to create a request to a URI, which requires us to login first. In order to process all the transactions, first we have to login and get the cookie value...
1
by: ALA | last post by:
Hi, does anybody know if it is possible to pass the SessionID with a web request by using a cookie so that the invoked page in the same domain can access the session objects of the current user?...
15
by: Nightcrawler | last post by:
I am currently using the HttpWebRequest and HttpWebResponse to pull webpages down from a few urls. string url = "some url"; HttpWebRequest httpWebRequest =...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.