Answered by:
The remote server returned an error: (401) Unauthorized

Question
-
Hello Everybody,
I'm using this code to get XmlDocument from url:
using (WebClient wc = new WebClient()) { wc.Credentials = new NetworkCredential("admin", "admin"); string xml = wc.DownloadString("http://192.168.1.187:8550/epe/pos/taglist"); XmlDocument tournamentsXML = new XmlDocument(); tournamentsXML.LoadXml(xml); XmlNodeList TagList = tournamentsXML.GetElementsByTagName("TAG"); foreach (XmlNode node in TagList) { XmlElement TagElement = (XmlElement)node; string TagID = TagElement.GetElementsByTagName("tagid")[0].InnerText; string MAC = TagElement.GetElementsByTagName("mac")[0].InnerText; Data.Add(new Tag(TagID,MAC)); } }
It's work fine,
But when I change the link to "http://192.168.1.187:8550/epe/pos/taglist?fields=posgood"
it give me error message "The remote server returned an error: (401) Unauthorized."By the way when I copy past the same link "http://192.168.1.187:8550/epe/pos/taglist?fields=posgood" to browser it retreive XML data exactly !!
Please help me please :(
Belal
- Moved by Jason Dot Wang Monday, March 25, 2013 9:25 AM Apache server is not Microsoft product
Monday, March 18, 2013 6:17 AM
Answers
-
Use fiddler to see what exactly those browsers send to the server and simulate that in your code. There are all kinds of reasons that you may get a 401, for example some servers limit verbs to Get or Put.
Visual C++ MVP- Proposed as answer by Jason Dot Wang Thursday, March 21, 2013 4:40 AM
- Marked as answer by Jason Dot Wang Monday, March 25, 2013 9:22 AM
Monday, March 18, 2013 9:19 PM
All replies
-
No any reply !!
Belal
Monday, March 18, 2013 9:08 AM -
Cut us some slack, it's in the middle of the night in the US.
Are you SURE the credentials in your browser are the same as what you set up in the program? 401 errors indicate authentication problems. Have you checked the configuration on that server?
Monday, March 18, 2013 9:51 AM -
I think you should ask this to your System Admin.
The IP address is located in your own network so your system admin should know
Otherwise try this microsoft forum
Success
CorMonday, March 18, 2013 10:45 AM -
Yes I'm trying to open it on IE and Firefox, it's work probably :(
Belal
Monday, March 18, 2013 11:09 AM -
Use fiddler to see what exactly those browsers send to the server and simulate that in your code. There are all kinds of reasons that you may get a 401, for example some servers limit verbs to Get or Put.
Visual C++ MVP- Proposed as answer by Jason Dot Wang Thursday, March 21, 2013 4:40 AM
- Marked as answer by Jason Dot Wang Monday, March 25, 2013 9:22 AM
Monday, March 18, 2013 9:19 PM -
Please any other help ,,,
Belal
Tuesday, March 19, 2013 6:29 AM -
Hi Shakatra,
Welcome to MSDN Forum Support.
Please take a look at Sheng Jiang 蒋晟's suggestions,his mentioned kb article has listed the detailed scenario about (401) Unauthorized.
Jason Wang [MSFT]
MSDN Community Support | Feedback to us
Thursday, March 21, 2013 4:43 AM -
But the server is Apache not IIS
Belal
Thursday, March 21, 2013 6:43 AM -
Hi Shakatra,
Welcome to MSDN Forum Support.
If your problem doesn't use the Microsoft technique or its related product, I am sorry that I can't support you due to its outside of the scope we should do. Hope you understand us. Furthermore, we need to move your thread to Off-topic.
Jason Wang [MSFT]
MSDN Community Support | Feedback to us
- Proposed as answer by Yasir Kamal Wednesday, June 12, 2013 12:39 PM
- Unproposed as answer by Yasir Kamal Wednesday, June 12, 2013 12:40 PM
Monday, March 25, 2013 9:24 AM