예제 #1
0
        private void SendPostRequest()
        {
            int    id      = random.Next(1000);
            string xmlData = "<Laptop>" +
                             "<BrandName>Alienware</BrandName>" +
                             "<Features>" +
                             "<Feature>8th Generation Intel® Core™ i5 - 8300H</Feature>" +
                             "<Feature>Windows 10 Home 64 - bit English</Feature>" +
                             "<Feature>NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6</Feature>" +
                             "<Feature>8GB, 2x4GB, DDR4, 2666MHz</Feature>" +
                             "</Features>" +
                             "<Id> " + id + "</Id>" +
                             "<LaptopName>Alienware M17</LaptopName>" +
                             "</Laptop>";


            Dictionary <string, string> headers = new Dictionary <string, string>()
            {
                { "Accept", "application/xml" }
            };

            RestResponse restResponse = httpClientAsyncHelper.PerformPostRequest(delayPostUrl, xmlData, xmlMediaType, headers).GetAwaiter().GetResult();

            //HttpContent httpContent = new StringContent(xmlData, Encoding.UTF8, xmlMediaType) ;
            //HttpClientHelper.PerformPostRequest(postUrl, httpContent, headers);

            Assert.AreEqual(200, restResponse.StatusCode);

            Console.WriteLine(">>>>>>>>>>" + restResponse.ResponseContent);

            Laptop xmlDatat = ResponseDataHelper.DeserializeXmlResponse <Laptop>(restResponse.ResponseContent);

            Console.WriteLine(xmlDatat.ToString());
        }
        private void sendpostrequest()
        {
            string contentxml = "<Laptop>" +
                                "<BrandName>Alienware</BrandName>" +
                                "<Features>" +
                                "<Feature>8th Generation Intel® Core™ i5-8300H</Feature>" +
                                "<Feature>Windows 10 Home 64-bit English</Feature>" +
                                "<Feature>NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6</Feature>" +
                                "<Feature>8GB, 2x4GB, DDR4, 2666MHz</Feature>" +
                                "</Features>" +
                                "<Id>" + id.ToString() + "</Id>" +
                                "<LaptopName>Alienware M16</LaptopName>" +
                                "</Laptop>";
            Dictionary <string, string> header = new Dictionary <string, string>
            {
                { "Accept", "application/xml" }
            };

            restResponse = httpClientAsyncHelper.PerformPostRequest(postdelayurl, contentxml, xmldataformat, header).GetAwaiter().GetResult();
            Assert.AreEqual(200, restResponse.StatusCode);

            Laptop xmlresponsedata = ResponseDataHelper.DeserializeXMLResponse <Laptop>(restResponse.ResponseContent);

            Console.WriteLine(xmlresponsedata.ToString());
        }