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

WebResponse error 401

Please help figure what I am doing wrong in this code. All I am trying to do is send come data to an aspx page and get some data back. I watched my variable in debug mode and can tell that I am reaching the web site but my data seems not to be posted. Also in debug mode I get error "Remote server returned error 401: Unautherized) at the "WebResponse Response = Request.GetResponse();" line and debugging stops. I have the required certificate required to access this site installed on my machine and can run a similar VB script and get resuilt back - but need to convert this to C#.

string sURL = "https://cabman/Purchase.aspx"
string cData = "<CABDETAILS CabNumber=""43877"" CabSKU=""6633"" ExpDate=""0106"" Postal=""78052"" />");
StringBuilder postData = new StringBuilder(cData);
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(sURL)
Request.ContentType="text/xml"
Request.ContentLength = postData.Length
Request.Method="POST"
//Request.KeepAlive = false
Stream newStream=Request.GetRequestStream()
StreamWriter sw = new StreamWriter(newStream)
sw.Write(postData.ToString())
sw.Close()

//Now we need to read the dat
WebResponse Response = Request.GetResponse()
HttpWebResponse httpRes = (HttpWebResponse)Response
Stream s = httpRes.GetResponseStream()
StreamReader sr = new StreamReader(s,Encoding.ASCII)
string returnDoc = sr.ReadToEnd()
sr.Close()

Thanks
Jacob
Nov 15 '05 #1
1 3154
Jacob wrote:
Please help figure what I am doing wrong in this code. All I am
trying to do is send come data to an aspx page and get some data
back. I watched my variable in debug mode and can tell that I am
reaching the web site but my data seems not to be posted. Also in
debug mode I get error "Remote server returned error 401:
Unautherized) at the "WebResponse Response = Request.GetResponse();"
line and debugging stops. I have the required certificate required to
access this site installed on my machine and can run a similar VB
script and get resuilt back - but need to convert this to C#.

[...]

You don't set your client certificate in the code you've posted. Check out
System.Net.HttpWebRequest's ClientCertificates property.

Cheers,

--
Joerg Jooss
jo*********@gmx.net

Nov 15 '05 #2

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

Similar topics

0
by: amine | last post by:
I really need help on this please. I am writing an application for an Ipaq and I am trying to enable the application to connect to a DAV server which can is basically an HTTP server that acts like...
6
by: Jonathan | last post by:
Calling the System.Net.WebResponse.GetResponse method (see code below) results in the following error: System.Net.WebException: The underlying connection was closed: An unexpected error occurred...
0
by: Johann Blake | last post by:
In my need to decode a JPEG 2000 file, I discovered like many that there was no functionality for this in the .NET Framework. Instead of forking out a pile of cash to do this, I came up with the...
2
by: gizmo | last post by:
Hi, I'm using the following code to request the html source from the quoted site. ...... string url = "http://www1.soccerstand.com/"; WebRequest webRequest = WebRequest.Create(url);...
2
by: Jeff G. | last post by:
Hello everyone, I have read through the newsgroups (thank God for 'em!) extensively looking for an example of how to pass a file (PDF) from a webresponse stream down to a web client. Here's the...
1
by: John | last post by:
I am in need to find a way to get the HTML from an internal URL. For example: I have page : default.aspx?page=Test, I need to get HTML of that page after rendering. At first thought, I would...
4
by: CindyH | last post by:
Hi I'm trying to use webrequest - webresponse to post a stream. I have set up a simple test with one aspx form holding the post code and trying to get another aspx form to receive the post on...
4
by: CindyH | last post by:
Hi - hope someone can help with this - this code was working for a while in the 'real' code and then suddenly stopped - not sure what happen. I made two simple forms on localhost to try to test...
0
by: deeps1512 | last post by:
hi All, I have written the following code to get a webresponse. XmlDocument myxmlDoc1 = new XmlDocument(); myxmlDoc1.LoadXml(BkXMLRQ); string s = myxmlDoc1.OuterXml;...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.