473,809 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "WebRespons e Response = Request.GetResp onse();" 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 = "<CABDETAIL S CabNumber=""438 77"" CabSKU=""6633"" ExpDate=""0106" " Postal=""78052" " />");
StringBuilder postData = new StringBuilder(c Data);
HttpWebRequest Request = (HttpWebRequest )WebRequest.Cre ate(sURL)
Request.Content Type="text/xml"
Request.Content Length = postData.Length
Request.Method= "POST"
//Request.KeepAli ve = false
Stream newStream=Reque st.GetRequestSt ream()
StreamWriter sw = new StreamWriter(ne wStream)
sw.Write(postDa ta.ToString())
sw.Close()

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

Thanks
Jacob
Nov 15 '05 #1
1 3169
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 "WebRespons e Response = Request.GetResp onse();"
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.Http WebRequest's ClientCertifica tes 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
1482
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 an FTP server. I used the following code WebRequest req = WebRequest.Create (url); req.Credentials = new NetworkCredential (username, pass); WebResponse res = req.GetResponse();
6
6152
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 on a receive. at(System.Net.HttpWebRequest.CheckFinalStatus()) at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at(System.Net.HttpWebRequest.GetResponse())
0
2768
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 idea that costs nothing and it is inheritently built into the Framework. So here is the solution... When you use the WebRequest and WebResponse classes to obtain graphics from a web site, these classes have built-in decoding for JPEG 2000 files....
2
9709
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); WebResponse webResponse = webRequest.GetResponse(); beginStr = new StreamReader(webResponse.GetResponseStream(),
2
3390
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 scenario - when the web browser requests a file, the IIS Server1 has to go back to Server2 to make a request for the file. Server2 then responds the file back to Server1 and Server1 should be able to just forward the file down to the web browser....
1
2367
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 use WebRequest to make a requestion, then use WebResponse to get the HTML. However, it won't work in my situation. The resaon for that is: WebRequestion needs a URI, which is in the format of http://<MyDomainName>/deafult.aspx?page=Test ... In my...
4
2085
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 localhost. Can you explain to me the possible reasons why a 'GetResponse' - to send the data to a server might not be working for a simple text file with one line. test.text - contains: this is a test.
4
2132
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 what is going on. I'm not getting any errors right now, but code is not working either - not reading the post in second form or else the first form is not sending it correctly....
0
1109
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; System.Text.ASCIIEncoding encoding1 = new System.Text.ASCIIEncoding(); Byte byt1 = encoding.GetBytes(myxmlDoc1.OuterXml);
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9601
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10637
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7660
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
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 we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.