title: HttpwebRequest - Exception from HRESULT: 0x800710DD
body: <p>I tried to send a cookie to Server. But when it does, it throws a weird exception I can not trace:</p>
  
  <pre><code>Message "The operation identifier is not valid. (Exception from HRESULT: 0x800710DD)"   string
  StackTrace  "   at Windows.Web.Http.Filters.HttpBaseProtocolFilter.SendRequestAsync(HttpRequestMessage request)\r\n   at System.Net.Http.HttpHandlerToFilter.&lt;SendAsync&gt;d__1.MoveNext()"    string
  </code></pre>
  
  <p>The line where the exception is thrown:</p>
  
  <pre><code>Request.BeginGetResponse( new AsyncCallback( GetResponseCallback ) , Request );
  </code></pre>
  
  <p>At the beginning I've never thought it was a cookie issue until I commented out this line:</p>
  
  <pre><code>WCRequest.CookieContainer = WBackgroundTransfer.Cookies;
  </code></pre>
  
  <p>The exception is gone if the line above is commented. So I tried another approach:</p>
  
  <pre><code>CookieContainer CC = new CookieContainer();
  CC.Add( new Cookie( "aa", "bb" ) );
  WCRequest.CookieContainer = CC;
  </code></pre>
  
  <p>The above line does not throw any exception. Then I proceed to modify my code:</p>
  
  <pre><code>CookieContainer CC = new CookieContainer();
  foreach( Cookie C in WBackgroundTransfer.Cookies.GetCookies( ReqURI ) )
  {
      CC.Add( new Cookie( C.Name, C.Value, C.Path, C.Domain ) );
  }
  WCRequest.CookieContainer = CC;
  </code></pre>
  
  <p>And the exception is back!</p>
  
  <p>Then I tried to modify the code again:</p>
  
  <pre><code>WCRequest.Headers[ HttpRequestHeader.Cookie ] = WBackgroundTransfer.Cookies.GetCookieHeader( ReqUri );
  </code></pre>
  
  <p>The exception still persist. The I modify the code to:</p>
  
  <pre><code>WCRequest.Headers[ HttpRequestHeader.Cookie ] = "ab=cd";
  </code></pre>
  
  <p>This works!</p>
  
  <p>So I think some of the cookie is causing this issue. I proceed to compare the server response.</p>
  
  <p>The exact cookie I am sending to server is:</p>
  
  <pre><code>PHPSESSID=j0g94fgvum0flhlop5868gjkklc5bh1v
  </code></pre>
  
  <p>When I send the above cookie to server, the response is:</p>
  
  <pre><code>HTTP/1.1 200 OK
  Date: Fri, 06 Nov 2015 16:51:13 GMT
  Content-Type: application/xml
  Transfer-Encoding: chunked
  Connection: keep-alive
  Set-Cookie: __cfduid=dd4e3badd19f3f67e86fe1431b7fe895a1446828673; expires=Sat, 05-Nov-16 16:51:13 GMT; path=/; domain=.example.com; HttpOnly
  Set-Cookie: PHPSESSID=j0g94fgvum0flhlop5868gjkklc5bh1v; path=/; HttpOnly
  Vary: Accept-Encoding
  Server: nginx
  CF-RAY: 24124d464d493439-HKG
  </code></pre>
  
  <p>When I send a random, irrelevant cookie, or not give any cookie to the sever:</p>
  
  <pre><code>HTTP/1.1 200 OK
  Date: Fri, 06 Nov 2015 16:53:24 GMT
  Content-Type: application/xml
  Transfer-Encoding: chunked
  Connection: keep-alive
  Set-Cookie: __cfduid=d0a29df98a2984c4f5c4b2ddbc900fde01446828804; expires=Sat, 05-Nov-16 16:53:24 GMT; path=/; domain=.example.com; HttpOnly
  Vary: Accept-Encoding
  Server: nginx
  CF-RAY: 2412507ad4c6330d-HKG
  </code></pre>
  
  <p>The only difference of the two request is this line:</p>
  
  <pre><code>Set-Cookie: PHPSESSID=j0g94fgvum0flhlop5868gjkklc5bh1v; path=/; HttpOnly
  </code></pre>
  
  <p>Which tells me to set the cookie where I sent to it.</p>
  
  <p>This is very frustrating. Is this an API bug? Or am I missing something? I cannot modify the sever behaviour so I am not 100% sure this is the cause.</p>
  
  <p>Any ideas?</p>
  
  <p>Update: This only happens in x64 platform! I am starting to think maybe this is a heisengbug...</p>
  
  <p>Update2: No, this happens on all platforms. I just didn't test it thoroughly:(</p>
  
  <p><strong>Update3: This is hopeless. I am going to try switching to socket to see if it helps</strong></p>