0

I'm trying to complete a PUT request to the IIS media services API - to try and set a publishing point to "stopped" state.

I've read the following link, which hasn't helped me very much! https://msdn.microsoft.com/en-us/library/hh206014%28VS.90%29.aspx

My current code throws an exception on the the httpWebRequest1.GetResponse(), it indicates the web server is returning a 401 unauthorized error code:

string url = "http://localhost/LiveStream.isml/State";

        var httpWebRequest1 = (HttpWebRequest)WebRequest.Create(url);
        httpWebRequest1.ContentType = "application/atom+xml";
        httpWebRequest1.Method = "PUT";
        httpWebRequest1.Headers.Add("Authorization", "USERNAME:PASSWORD");


        using (var streamWriter = new StreamWriter(httpWebRequest1.GetRequestStream()))
        {
            XmlDocument document = new XmlDocument();
            document.Load("Resources/XMLFile1.xml");
            string test = GetXMLAsString(document);

            streamWriter.Write(test);
        }
        var httpResponse = (HttpWebResponse)httpWebRequest1.GetResponse();
        using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
        {
            var responseText = streamReader.ReadToEnd();

        }

My Username/password was commented out, but they work fine when visiting the page in a browser, and inputting them in the username/password form that opens.

My Script essentially "PUT"s an XML document that is a copy of the XML document returned when visiting the state page in a browser.

Any help would be appreciated.

Phil Golding
  • 433
  • 3
  • 10
  • Disable the WebDav native module. See: http://stackoverflow.com/questions/28579073/how-to-get-put-and-delete-verbs-to-work-with-webapi-on-iis – Kev Nov 13 '15 at 17:10
  • Hi Kev, thanks for the suggestion - WebDav is already disabled on the website in IIS. – Phil Golding Nov 13 '15 at 17:32
  • Ok...then now I'd enable Failed Request Tracing to see what's going on under the bonnet. That should tell you which module or place in the request pipeline that's raising the 401. See my previous answer about this: http://stackoverflow.com/a/5484991/419 – Kev Nov 13 '15 at 22:28

0 Answers0