You must write ContentLength bytes to the request stream before calling [Begin]GetRes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • uncletone1
    Junior Member
    • Oct 2012
    • 24

    #1

    You must write ContentLength bytes to the request stream before calling [Begin]GetRes

    Hi
    I'm getting an error in my code. It was working a while ago, but for some reason I can't seem to see where it might be wrong now.

    Thanks

    try
    {
    HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("https://api.betfair.com/exchange/betting/json-rpc/v1");

    if (MyProxy != null)
    {
    httpWebRequest.Proxy = MyProxy;
    }

    NameValueCollection CustomHeaders = new NameValueCollection();
    CustomHeaders["X-Application"] = AppKey;
    CustomHeaders["X-Authentication"] = SessionToken;
    httpWebRequest.ContentType = "application/x-www-form-urlencoded";
    httpWebRequest.Accept = "application/json";
    httpWebRequest.Method = WebRequestMethods.Http.Post;
    httpWebRequest.Headers.Add(HttpRequestHeader.Accep tCharset, "ISO-8859-1,utf-8");
    httpWebRequest.Headers.Add(CustomHeaders);

    Byte[] BA = Encoding.UTF8.GetBytes(Output);
    httpWebRequest.ContentLength = BA.Length;

    Stream SW = httpWebRequest.GetRequestStream();
    SW.Write(BA, 0, BA.Length);

    ------- Failing here
    HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

    Stream Reader = httpResponse.GetResponseStream();
    StreamReader Sreader = new StreamReader(Reader);

    String IN = Sreader.ReadToEnd();
    return IN;

    }
    catch (Exception e)
    {
    return "ERROR : " + e.ToString();
    }
  • uncletone1
    Junior Member
    • Oct 2012
    • 24

    #2
    Sorted.

    Expect100Continue = false

    Thanks for looking

    Comment

    • john_baptiste_of_cheshire
      Junior Member
      • Apr 2012
      • 8

      #3
      thanks :-)
      Last edited by john_baptiste_of_cheshire; 19-09-2016, 12:03 AM.

      Comment

      Working...
      X