locked
Send data to REST service RRS feed

  • Question

  • hi,

      I would like to send data to my REST Service provider. If I only receive data everything works ok but when I send data I got error: The request was aborted: The request was canceled

    I tried sent data in  Content-Type: text/json or text/html. I always got above error.

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(subscriptionAdd);
    
    string postData = "email=test%40test.pl&subject=test+emaila"; //for text/html
    postData = "{subscriber:test@test.pl}"; //for text/json
    
    request.ContentLength = postData.Lenght;
    
    string sha1String = APIKey + "/rest/subscriber/add" + postData + APISecret;
    string XRestApiSign = SHA1HashStringForUTF8String(sha1String);
    
    request.Method = WebRequestMethods.Http.Post;
    request.ContentType = "text/json";
    request.Headers.Add("X-Rest-ApiSign", XRestApiSign);
    request.Headers.Add("X-Rest-ApiKey", APIKey);
    
    request.ContentLength = postData.Length;
    
    StreamWriter requestWriter;
    Stream webStream = request.GetRequestStream();
    
    requestWriter = new StreamWriter(webStream, System.Text.Encoding.UTF8);
    requestWriter.Write(postData);
    requestWriter.Close();

    Do you see any bug in code?

    I tried send data like byte[] then I don't get error but my service provider return 401 unathorized. Maybe I wrong but data in byte[] type isn't identical to json or html content type..



    Best regards Jacek

    • Moved by Eason_H Monday, December 9, 2013 2:18 AM
    Friday, December 6, 2013 10:15 AM

Answers

  • Hi Lutador83,

    Since the issue regards webservice and website deployment. I suggestion you post the question in the ASP.NET forums at http://forums.asp.net/. It is appropriate and more experts will assist you.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Just Karl Wednesday, January 8, 2014 9:51 PM
    • Marked as answer by Just Karl Thursday, January 16, 2014 6:25 PM
    Monday, December 9, 2013 2:17 AM