locked
Error during sent data to REST Service RRS feed

  • Question

  • User-604655155 posted

    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..

    Monday, December 9, 2013 2:24 AM

All replies

  • User-488622176 posted

    are you sure no exceptions were thrown from within the service?

    Thursday, December 12, 2013 12:39 PM
  • User-604655155 posted

    I didn't receive email with your answer so I'm replying with big delay :)

    I asked service provicer about this error and I got answer:  "that connection does not pass verification and .net report it like this"

    I made conscious mistake in sha1String. To check that I connect to service. I got error "The request was aborted: The request was canceled" so this error is from my .net not from service provider.

     

    Monday, December 23, 2013 3:42 AM