I am trying to create a Bug but using the following POST fails with a 401 when a GET does authenticate. I appreciate this is fundamentally a write rather than a read but the AD user role does have Add/Edit permissions. what am i missing?
Thanks
private static XmlDocument restPost(string url, string userName, string userPassword, string domain, string xmlPost) { var request = WebRequest.Create(new Uri(url)) as HttpWebRequest; var xd = new XmlDocument(); if (request != null) { request.Method = WebRequestMethods.Http.Post; string postData = string.Format(xmlPost); byte[] data = Encoding.UTF8.GetBytes(postData);
On Wednesday, October 3, 2012 2:50:44 PM UTC+3, Max Foulds wrote:
> I am trying to create a Bug but using the following POST fails with a 401 > when a GET does authenticate. I appreciate this is fundamentally a write > rather than a read but the AD user role does have Add/Edit permissions. > what am i missing?
> Thanks
> private static XmlDocument restPost(string url, string userName, string userPassword, string domain, string xmlPost) > { > var request = WebRequest.Create(new Uri(url)) as HttpWebRequest; > var xd = new XmlDocument(); > if (request != null) > { > request.Method = WebRequestMethods.Http.Post; > string postData = string.Format(xmlPost); > byte[] data = Encoding.UTF8.GetBytes(postData);
On Friday, October 5, 2012 1:48:31 PM UTC+1, Alex Fomin wrote:
> Hi Max,
> You code is correct. Do you use on-demand or on-site TP? What value do you > pass to "domain" parameter? What is the body of a 401 response?
> Thanks, > Alex
> On Wednesday, October 3, 2012 2:50:44 PM UTC+3, Max Foulds wrote:
>> I am trying to create a Bug but using the following POST fails with a 401 >> when a GET does authenticate. I appreciate this is fundamentally a write >> rather than a read but the AD user role does have Add/Edit permissions. >> what am i missing?
>> Thanks
>> private static XmlDocument restPost(string url, string userName, string userPassword, string domain, string xmlPost) >> { >> var request = WebRequest.Create(new Uri(url)) as HttpWebRequest; >> var xd = new XmlDocument(); >> if (request != null) >> { >> request.Method = WebRequestMethods.Http.Post; >> string postData = string.Format(xmlPost); >> byte[] data = Encoding.UTF8.GetBytes(postData);
On Thursday, October 18, 2012 11:55:45 AM UTC+3, Max Foulds wrote:
> We are using on-site TP and I am passing in the fully qualified domain > name into the post
> On Friday, October 5, 2012 1:48:31 PM UTC+1, Alex Fomin wrote:
>> Hi Max,
>> You code is correct. Do you use on-demand or on-site TP? What value do >> you pass to "domain" parameter? What is the body of a 401 response?
>> Thanks, >> Alex
>> On Wednesday, October 3, 2012 2:50:44 PM UTC+3, Max Foulds wrote:
>>> I am trying to create a Bug but using the following POST fails with a >>> 401 when a GET does authenticate. I appreciate this is fundamentally a >>> write rather than a read but the AD user role does have Add/Edit >>> permissions. what am i missing?
>>> Thanks
>>> private static XmlDocument restPost(string url, string userName, string userPassword, string domain, string xmlPost) >>> { >>> var request = WebRequest.Create(new Uri(url)) as HttpWebRequest; >>> var xd = new XmlDocument(); >>> if (request != null) >>> { >>> request.Method = WebRequestMethods.Http.Post; >>> string postData = string.Format(xmlPost); >>> byte[] data = Encoding.UTF8.GetBytes(postData);
On Thursday, October 18, 2012 12:23:59 PM UTC+1, Alex Fomin wrote:
> Do you use win authentication? If so, what is the body of 401 response?
> On Thursday, October 18, 2012 11:55:45 AM UTC+3, Max Foulds wrote:
>> We are using on-site TP and I am passing in the fully qualified domain >> name into the post
>> On Friday, October 5, 2012 1:48:31 PM UTC+1, Alex Fomin wrote:
>>> Hi Max,
>>> You code is correct. Do you use on-demand or on-site TP? What value do >>> you pass to "domain" parameter? What is the body of a 401 response?
>>> Thanks, >>> Alex
>>> On Wednesday, October 3, 2012 2:50:44 PM UTC+3, Max Foulds wrote:
>>>> I am trying to create a Bug but using the following POST fails with a >>>> 401 when a GET does authenticate. I appreciate this is fundamentally a >>>> write rather than a read but the AD user role does have Add/Edit >>>> permissions. what am i missing?
>>>> Thanks
>>>> private static XmlDocument restPost(string url, string userName, string userPassword, string domain, string xmlPost) >>>> { >>>> var request = WebRequest.Create(new Uri(url)) as HttpWebRequest; >>>> var xd = new XmlDocument(); >>>> if (request != null) >>>> { >>>> request.Method = WebRequestMethods.Http.Post; >>>> string postData = string.Format(xmlPost); >>>> byte[] data = Encoding.UTF8.GetBytes(postData);
On Thursday, October 18, 2012 4:53:08 PM UTC+1, Max Foulds wrote:
> Yes we are using win authentication and It is responding with a "The > remote server returned an error: (401) Unauthorized."
> Just to clarify, the same account has no problems doing a request before > it tries a post.
> On Thursday, October 18, 2012 12:23:59 PM UTC+1, Alex Fomin wrote:
>> Do you use win authentication? If so, what is the body of 401 response?
>> On Thursday, October 18, 2012 11:55:45 AM UTC+3, Max Foulds wrote:
>>> We are using on-site TP and I am passing in the fully qualified domain >>> name into the post
>>> On Friday, October 5, 2012 1:48:31 PM UTC+1, Alex Fomin wrote:
>>>> Hi Max,
>>>> You code is correct. Do you use on-demand or on-site TP? What value do >>>> you pass to "domain" parameter? What is the body of a 401 response?
>>>> Thanks, >>>> Alex
>>>> On Wednesday, October 3, 2012 2:50:44 PM UTC+3, Max Foulds wrote:
>>>>> I am trying to create a Bug but using the following POST fails with a >>>>> 401 when a GET does authenticate. I appreciate this is fundamentally a >>>>> write rather than a read but the AD user role does have Add/Edit >>>>> permissions. what am i missing?
>>>>> Thanks
>>>>> private static XmlDocument restPost(string url, string userName, string userPassword, string domain, string xmlPost) >>>>> { >>>>> var request = WebRequest.Create(new Uri(url)) as HttpWebRequest; >>>>> var xd = new XmlDocument(); >>>>> if (request != null) >>>>> { >>>>> request.Method = WebRequestMethods.Http.Post; >>>>> string postData = string.Format(xmlPost); >>>>> byte[] data = Encoding.UTF8.GetBytes(postData);
We still need a full body of 401 response including all headers to determine whether this response is caused by IIS itself (that means that there is some issues with IIS configs) or by TP (in case of bugs). Also have you tried to send POST requests with 3rd party tools like Fiddler? It will insert required Windows credentials if IIS is configured correctly. Also you can sniff the full IIS response using fiddler as well.
On Thursday, October 18, 2012 6:54:57 PM UTC+3, Max Foulds wrote:
> That was meant to say no problem doing a GET before it tries to POST :)
> On Thursday, October 18, 2012 4:53:08 PM UTC+1, Max Foulds wrote:
>> Yes we are using win authentication and It is responding with a "The >> remote server returned an error: (401) Unauthorized."
>> Just to clarify, the same account has no problems doing a request before >> it tries a post.
>> On Thursday, October 18, 2012 12:23:59 PM UTC+1, Alex Fomin wrote:
>>> Do you use win authentication? If so, what is the body of 401 response?
>>> On Thursday, October 18, 2012 11:55:45 AM UTC+3, Max Foulds wrote:
>>>> We are using on-site TP and I am passing in the fully qualified domain >>>> name into the post
>>>> On Friday, October 5, 2012 1:48:31 PM UTC+1, Alex Fomin wrote:
>>>>> Hi Max,
>>>>> You code is correct. Do you use on-demand or on-site TP? What value do >>>>> you pass to "domain" parameter? What is the body of a 401 response?
>>>>> Thanks, >>>>> Alex
>>>>> On Wednesday, October 3, 2012 2:50:44 PM UTC+3, Max Foulds wrote:
>>>>>> I am trying to create a Bug but using the following POST fails with a >>>>>> 401 when a GET does authenticate. I appreciate this is fundamentally a >>>>>> write rather than a read but the AD user role does have Add/Edit >>>>>> permissions. what am i missing?
>>>>>> Thanks
>>>>>> private static XmlDocument restPost(string url, string userName, string userPassword, string domain, string xmlPost) >>>>>> { >>>>>> var request = WebRequest.Create(new Uri(url)) as HttpWebRequest; >>>>>> var xd = new XmlDocument(); >>>>>> if (request != null) >>>>>> { >>>>>> request.Method = WebRequestMethods.Http.Post; >>>>>> string postData = string.Format(xmlPost); >>>>>> byte[] data = Encoding.UTF8.GetBytes(postData);
Thanks for the direct toward sniffing at the post. It enabled me to get to the bottom of the problem which was 2 fold. My code that I had posted above was incorrect in that the 2 following lines should have been further up the method logic
request.Credentials = new NetworkCredential(userName, userPassword, domain); request.PreAuthenticate = true;
I noticed that there was a post which failed with "401 - Unauthorized: Access is denied due to invalid credentials" with an empty negotiation string and then there was a second post using a encoded negotiation string which then successfully authenticated however my XML was badly formed as I got a bad response which I managed to fix. Anyway problem now solved. See below for my updated working REST post
private static XmlDocument restPost(string url, string userName, string userPassword, string domain, string xmlPost) { var request = WebRequest.Create(new Uri(url)) as HttpWebRequest; var xd = new XmlDocument(); if (request != null) { request.Method = WebRequestMethods.Http.Post; string postData = string.Format(xmlPost); byte[] data = Encoding.UTF8.GetBytes(postData);
On Thursday, 8 November 2012 08:33:56 UTC, Alex Fomin wrote:
> Hi Max,
> We still need a full body of 401 response including all headers to > determine whether this response is caused by IIS itself (that means that > there is some issues with IIS configs) or by TP (in case of bugs). Also > have you tried to send POST requests with 3rd party tools like Fiddler? It > will insert required Windows credentials if IIS is configured correctly. > Also you can sniff the full IIS response using fiddler as well.
> On Thursday, October 18, 2012 6:54:57 PM UTC+3, Max Foulds wrote:
>> That was meant to say no problem doing a GET before it tries to POST :)
>> On Thursday, October 18, 2012 4:53:08 PM UTC+1, Max Foulds wrote:
>>> Yes we are using win authentication and It is responding with a "The >>> remote server returned an error: (401) Unauthorized."
>>> Just to clarify, the same account has no problems doing a request before >>> it tries a post.
>>> On Thursday, October 18, 2012 12:23:59 PM UTC+1, Alex Fomin wrote:
>>>> Do you use win authentication? If so, what is the body of 401 response?
>>>> On Thursday, October 18, 2012 11:55:45 AM UTC+3, Max Foulds wrote:
>>>>> We are using on-site TP and I am passing in the fully qualified domain >>>>> name into the post
>>>>> On Friday, October 5, 2012 1:48:31 PM UTC+1, Alex Fomin wrote:
>>>>>> Hi Max,
>>>>>> You code is correct. Do you use on-demand or on-site TP? What value >>>>>> do you pass to "domain" parameter? What is the body of a 401 response?
>>>>>> Thanks, >>>>>> Alex
>>>>>> On Wednesday, October 3, 2012 2:50:44 PM UTC+3, Max Foulds wrote:
>>>>>>> I am trying to create a Bug but using the following POST fails with >>>>>>> a 401 when a GET does authenticate. I appreciate this is fundamentally a >>>>>>> write rather than a read but the AD user role does have Add/Edit >>>>>>> permissions. what am i missing?
>>>>>>> Thanks
>>>>>>> private static XmlDocument restPost(string url, string userName, string userPassword, string domain, string xmlPost) >>>>>>> { >>>>>>> var request = WebRequest.Create(new Uri(url)) as HttpWebRequest; >>>>>>> var xd = new XmlDocument(); >>>>>>> if (request != null) >>>>>>> { >>>>>>> request.Method = WebRequestMethods.Http.Post; >>>>>>> string postData = string.Format(xmlPost); >>>>>>> byte[] data = Encoding.UTF8.GetBytes(postData);