none
CUrl to RestRequest RRS feed

  • Question

  • Hi,
        i want to convert Curl request into C# equivalent. Please advise me on that :
    the request is:
    curl -X PUT 'https://---------------/ws-------/services/rest/ordering/cart' -u username:password -H 'Content-Type: application/json' -H 'Accept: application/json' --data-binary $'{"customerReference" : "Client #12345","description" : "Cart for client #12345"}'
     thanks in advance :)
    Wednesday, December 16, 2015 9:46 AM

Answers

  • Hi,Nafees

    Please try the following.

       HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://---------------/ws-------/services/rest/ordering/cart");
       request.Credentials = new NetworkCredential("username", "password"); ;
       request.Method = "PUT";
       request.ContentType = "application/json";
       request.Accept = "application/json";
       byte[] buffer = Encoding.GetEncoding("UTF-8").GetBytes("{\"customerReference\" : \"Client #12345\",\"description\" : \"Cart for client #12345\"}");
       string result = System.Convert.ToBase64String(buffer);
       Stream reqstr = request.GetRequestStream();
       reqstr.Write(buffer, 0, buffer.Length);
       reqstr.Close();
    
       WebResponse response = request.GetResponse();
       response.Close(); ;

    Best regards,

    Chris Zhao

    • Proposed as answer by Pengzhen Song Thursday, January 7, 2016 2:08 AM
    • Marked as answer by Pengzhen Song Thursday, January 7, 2016 2:08 AM
    Thursday, December 17, 2015 4:43 PM