PUT API request - (IIS media services API)

58 Views Asked by At

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.

0

There are 0 best solutions below