PostAsync coreclr send different request compare to PostAsync clr
When I send a PostAsync request in clr using (GAC_MSIL\System.Net.Http\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll) the request is accepted.
But sending the same request in coreclr using (System.Net.Http\4.0.1-beta-23516\ref\dotnet5.2\System.Net.Http.dll) the request is not accepted
Code used
var x = new HttpClient();
x.BaseAddress = new Uri("https://leerlingen.trinitascollege.nl");
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("wu_loginname","name"),
new KeyValuePair<string, string>("wu_password","password"),
new KeyValuePair<string, string>("path","/")
});
var result = await x.PostAsync("/login?passAction=login", content);
Fiddler raw request coreclr request
POST https://leerlingen.trinitascollege.nl/login?passAction=login HTTP/1.1
Connection: Keep-Alive
Content-Type: application/x-www-form-urlencoded
Host: leerlingen.trinitascollege.nl
Content-Length: 49
Accept-Encoding: gzip, deflate
wu_loginname=name&wu_password=password&path=%2F
coreclr response
HTTP/1.1 302 Moved Temporarily
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=B25FE445133AF103021C6B9FD731FEC2; Path=/; Secure; HttpOnly
Cache-control: no-cache
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Pragma: no-cache
Connection: close
location: /
Content-Type: text/html;charset=UTF-8
Content-Language: nl-NL
Content-Length: 117
Date: Sun, 06 Mar 2016 16:02:23 GMT
<html>
<head>
<title>Document Moved</title>
</head>
<body>
<h1>Object Moved</h1>
<a HREF="/">here</a>
</body>
</html>
clr request
POST https://leerlingen.trinitascollege.nl/login?passAction=login HTTP/1.1
Connection: Keep-Alive
Content-Type: application/x-www-form-urlencoded
Host: leerlingen.trinitascollege.nl
Content-Length: 49
Expect: 100-continue
wu_loginname=name&wu_password=password&path=%2F
clr response
HTTP/1.1 302 Moved Temporarily
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=6CFCD4313BB8B24B1BC65F246C4346F1; Path=/; Secure; HttpOnly
Cache-control: no-cache
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Pragma: no-cache
Connection: close
location: /
Content-Type: text/html;charset=UTF-8
Content-Language: nl-NL
Content-Length: 117
Date: Sun, 06 Mar 2016 16:05:55 GMT
<html>
<head>
<title>Document Moved</title>
</head>
<body>
<h1>Object Moved</h1>
<a HREF="/">here</a>
</body>
</html>
Expect: 100-continue
This header would never be sent in the CoreClr (CoreFx) version of our HTTP stack. Expect 100-continue is not supported at all and our client stacks would never insert that header. So, I don't understand these traces.
the request is not accepted
Can you post the response headers as well?
I updated the issue. I saw that I swaped the clr with coreclr so I changed that also
The only thing that's is different is the
Accept-Encoding: gzip, deflate and Expect: 100-continue
Thx for updating the issue.
But I still don't see what the problem is.
You say
the request is not accepted
But both responses give back a 302 redirection response. Are there more traces after that?
I don't understand it also. I did the following test
Made a post request with the example program and clr that let me login to the site
Capture the raw request with fiddler
Execute that same raw request with fiddle. But this request would not login me on to the site.???
Both get a 302 but the first one has a sessionID of a valid user login and the second is invalid Both will be redirected to the root but the second wil get the login page again
see the two request in fiddler

It seems that the Set-Cookie header in the 302 HTTP response is getting lost and that is why you're seeing login page again.
This bug was fixed in December 2015 in PR dotnet/corefx#5001.
Since you are using an older package on NuGet.org, that package doesn't have the fix.
You might want to try the latest set of packages on CoreFx myget feed. Or wait until the next pre-release set of packages are published to NuGet.org. That should happen in the next few weeks.
Found a way to reproduce this issue
The difference between coreclr and clr is the request to / after the 302 In clr the JSSessionID is posted with the request. But in coreclr the request is without JSSESSIONID
probably this is how the site logs you in. You get a sessionID and that sessionID must be send to the root site to login
clr
GET https://leerlingen.trinitascollege.nl/ HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: leerlingen.trinitascollege.nl
Cookie: JSESSIONID=A5C255BEC0B9E23DFCD885B37C360482
coreclr
GET https://leerlingen.trinitascollege.nl/ HTTP/1.1
Host: leerlingen.trinitascollege.nl
Oke, that's seems indeed the problem. Thanks I will try that
We'll close this issue now. Please open it back up if trying latest packages doesn't solve it. Thx.
It's still remains one issue.
Accept-Encoding: gzip, deflate
I don't want to send gzip nor deflate as accepted encoding.
Even if I clear the default request headers:
httpClient.DefaultRequestHeaders.AcceptEncoding.Clear();
On targeting coreclr the .PostAsync(...) (didn't checked if anything else doing the same thing) append to it on the fly, but targeting clr doesn't and I think that's the normal behaviour.
pkg ver
"System.Net.Http": "4.0.1-beta-23516"
Is this legitimate? Or I should do a workaround..?
There is a difference between CLR and CoreCLR w.r.t how automatic decompression works. On CLR, it is off by default and so the 'Accept-Encoding' headers are empty. On CoreCLR, the default for automatic decompression is true and so the headers get populated.
You can turn off automatic decompression by setting the appropriate property on the HttpClientHandler. When you turn off automatic decompression, it will leave the 'Accept-Encoding' headers blank.
Example code:
var handler = new HttpClientHandler();
handler.AutomaticDecompression = false;
var client = new HttpClient(handler);
// ... other code to send requests
That's it! Never thought about that. Thanks!