473,385 Members | 1,630 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,385 software developers and data experts.

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 3173
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 =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.