예제 #1
0
        /*
         * <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
         * <s:Header>
         * <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://www.onvif.org/ver10/device/wsdl/GetNTP</Action>
         * </s:Header>
         * <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
         * <GetNTP xmlns="http://www.onvif.org/ver10/device/wsdl" />
         * </s:Body>
         * </s:Envelope>
         */

        private void buttonRest_Click(object sender, EventArgs e)
        {
            // this works with HTTP 400
            // and does not work with HTTPS
            try
            {
                using (HttpClient client = new HttpClient(tbAddress.Text))
                {
                    System.Xml.XmlDocument doc = new XmlDocument();
                    doc.LoadXml(tbRequest.Text);

                    System.Xml.Linq.XElement element = XElement.Parse(tbRequest.Text);
                    HttpContent content = HttpContentExtensions.Create(element);

                    using (HttpResponseMessage response = client.Post("/Dut.asmx", content))
                    {
                        response.Content.LoadIntoBuffer();
                        Console.WriteLine("  Status Code: {0}", response.StatusCode);
                        string cnt = response.Content.ReadAsString();
                        Console.WriteLine("  Content: {0}", cnt);
                        tbResponse.Text = cnt;
                    }
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }