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

Home Posts Topics Members FAQ

errors running HttpWebRequest.GetResponse - 401 unauthorized

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 errors on the
HttpWebRequest.GetResponse statement.

The remote server returned an error: (401) Unauthorized

also, when I use the network credentials object in the context of my
request, I get this error:

The underlying connection was closed: The server committed
an HTTP protocol violation.

Here is the web page I have prepared as I do battle with the godaddy
techs.
www.autocoder.com/demosite/AmazonQuery.aspx

click away at it, I dont think any harm can be done.

A code snippet follows. I am working under the assumption that the
problem resides with the config of the godaddy servers. Is there
something that has to be enabled in order for my asp.net code to send a
web request to another site? Are there magic words I can use to
convince the godaddy techs to this affect?

thanks,

-Steve

private void WebRequestTest( string InURL )
{
string line ;
StringBuilder sb = new StringBuilder( ) ;
HttpWebResponse resp ;
HttpWebRequest rqs = (HttpWebRequest)WebRequest.Create( InURL ) ;
rqs.MaximumAutomaticRedirections = 4;
rqs.MaximumResponseHeadersLength = 4;
// either user default credentials or the credentials specified on the
page.
if ( CheckBox1.Checked == false )
rqs.Credentials = CredentialCache.DefaultCredentials;
else
rqs.Credentials = new NetworkCredential( tbUser.Text,
tbPassword.Text, tbDomain.Text ) ;

// send the request to the remote site, get the response.
resp = (HttpWebResponse)rqs.GetResponse( ) ;

Nov 19 '05 #1
2 14068
this error was corrected by godaddy providing me with a url of a proxy
server to use on my web requests:

HttpWebResponse resp = null ;
HttpWebRequest rqs = (HttpWebRequest)WebRequest.Create( InURL ) ;
string ProxyUrl = ConfigurationSettings.AppSettings["WebRequestProxy"]
;
if ( ProxyUrl != null )
{
WebProxy proxy = new WebProxy( ProxyUrl ) ;
rqs.Proxy = proxy ;
}
resp = (HttpWebResponse)rqs.GetResponse( ) ;

-Steve

Steve Richter wrote:
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 errors on the HttpWebRequest.GetResponse statement.

The remote server returned an error: (401) Unauthorized

also, when I use the network credentials object in the context of my
request, I get this error:

The underlying connection was closed: The server committed
an HTTP protocol violation.

Here is the web page I have prepared as I do battle with the godaddy
techs.
www.autocoder.com/demosite/AmazonQuery.aspx

click away at it, I dont think any harm can be done.

A code snippet follows. I am working under the assumption that the
problem resides with the config of the godaddy servers. Is there
something that has to be enabled in order for my asp.net code to send a web request to another site? Are there magic words I can use to
convince the godaddy techs to this affect?

thanks,

-Steve

private void WebRequestTest( string InURL )
{
string line ;
StringBuilder sb = new StringBuilder( ) ;
HttpWebResponse resp ;
HttpWebRequest rqs = (HttpWebRequest)WebRequest.Create( InURL ) ;
rqs.MaximumAutomaticRedirections = 4;
rqs.MaximumResponseHeadersLength = 4;
// either user default credentials or the credentials specified on the page.
if ( CheckBox1.Checked == false )
rqs.Credentials = CredentialCache.DefaultCredentials;
else
rqs.Credentials = new NetworkCredential( tbUser.Text,
tbPassword.Text, tbDomain.Text ) ;

// send the request to the remote site, get the response.
resp = (HttpWebResponse)rqs.GetResponse( ) ;


Nov 19 '05 #2
"Steve Richter" <St************@gmail.com> wrote in message
news:St************@gmail.com:
also, when I use the network credentials object in the context of my
request, I get this error:

The underlying connection was closed: The server committed
an HTTP protocol violation.


It sounds like you're using 1.1... If so, try this in your config file:

<configuration>
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>
</configuration>

It seems most servers break the RFC and use spaces in their headers.
useUnsafeHeaderParsing fixed the problem for me...

-shane

Nov 19 '05 #3

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

Similar topics

1
3186
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...
10
19306
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
3
15721
by: ME | last post by:
Hi; I am getting "Unhandled Exception: System.Net.WebException: The remote server returned an erro r: (401) Unauthorized." when I am trying to get a page via post. Code follows...
0
1207
by: Dave | last post by:
Hi, I'm trying to make a WebRequest to url using the code below. The url points to a large number XML files on my shared dev server via a virtual folder secured using basic authentication. I did...
1
2777
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...
0
2364
by: Pmcg | last post by:
I would appreciate any help with the following, havn't found any answers for this in my research to date. I am trying to retreive a web page (a htm file intially) from a vdir on an intranet site...
0
1865
by: Cozfer | last post by:
I am having a problem communicating with a remote server (on intranet) using the httpwebrequest object. We have used the object to communicate with other machines previously, but this time we must...
2
1170
by: neoret | last post by:
I don't get any further on this - pleas help me :) In c# I'm using the httpWebRequest object to post a word-document along with some parameters to a server. My challenges are: 1. When creating...
0
1409
by: ashurack | last post by:
I can't seem to get this to work. The URL I want to access is protected with windows authentication. I thought that was NTLM but the following isn't working: string url =...
0
7075
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
7089
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
7088
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...
0
5388
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
4811
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
3027
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1326
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
580
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
223
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.