-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No charset in url-encoded form in RestSharp 109.0.1 #2037
Comments
Do you have an example of the raw response? How did the cookies work in previous versions, were you able to get the cookies in the client container? |
With 108/.NET 6.0 the cookie is in the restresponse Cookies collection and in the restclient CookieContainer as expected. |
You can send the request to requestbin using both versions and compare them. It's usually obvious what the difference is. |
The only difference I can see is that the restrequest Parameters with 108 has no content type and on .NET 6.0 this works for authentication: with 109 the same parameter in Parameters look like this: It seems if the ContentType is set in the request param to 'text/plain' then the authentication fails, so no cookie. (for the testing I rolled back the function to .NET 6.0 so I'm using the same configuration/username/password for both cases for the Azure function, so the username cannot be not the same for the two test cases) |
We took the default content type from botnet runtime code https://github.com/dotnet/runtime/blob/e21b7ea213386701a4904c70c09005c9bc3cb95c/src/libraries/System.Net.Http/src/System/Net/Http/StringContent.cs#L16 As I suggested, if you make your requests to requestbin, you will see the actual difference. Inspecting parameters doesn't tell you how the raw request looks like. |
here are two requests sent from the same function to requestbin/pipedream: ================================================================== username=asg&password=sdfgd ====================================================================== username=asg&password=sdfgd =================================================================== |
RestSharp doesn't touch the content type charset unless the |
both of these are from .NET 6.0. It seems the new restsharp 109 doesn't put the charset in the query, and the authentication fails without that, while 108 and earlier did. This is the code I used to generate the requests:
So 109 doesn't work for me regardless of the .NET version, because it omits the charset and without that the authentication fails. (so no cookie) So how can I add the charset to to 109 or how can I add the contentType to 108 in order to make any of them work on .NET 7.0? |
I am not sure what exactly happens because there's a test that makes a call with multi-part form and it ensures that the charset is there as part of the content type: RestSharp/test/RestSharp.Tests.Integrated/MultipartFormDataTests.cs Lines 25 to 32 in 93ca86a
|
Ok, wrong test. It's the multi-part and your request uses url-encoded |
I don't see any changes in this code for almost a year. Have no idea why the behaviour could change var formContent = new FormUrlEncodedContent(
postParameters
.Select(x => new KeyValuePair<string, string>(x.Name!, x.Value?.ToString() ?? string.Empty))!
);
Content = formContent; |
The only way the charset is getting set now is when the compilation branch for .NET Framework or .NET Standard is used. But not .NET 6 or 7. The |
I encountered the same problem. console.exe x86 at win11 22h2 test:
|
Describe the bug
no cookie in the restresponse cookies containter with .NET 7.0 and RestSharp 109.0.1
To Reproduce
The exact same code returns a cookie on .NET 6 and RestSharp 108.0.3
Stack trace
no exception or any errors
Desktop (please complete the following information):
Additional context
The differences in the restresponse between the two versions:
108
ContentHeaders: (there is only 1, and the ContentType is empty)
{HeaderParameter { Name = Content-Type, Value = text/html; charset=utf-8, Type = HttpHeader, Encode = False, ContentType = }}
ContentLength = null
RawBytes = {byte[695223]}
109
ContentHeaders: (there are 1, and the ContentType is text/plain)
{HeaderParameter { Name = Content-Type, Value = text/html; charset=utf-8, Type = HttpHeader, Encode = False, ContentType = text/plain }}
{HeaderParameter { Name = Content-Length, Value = 2352, Type = HttpHeader, Encode = False, ContentType = text/plain }}
ContentLength = 2352
RawBytes = {byte[2352]}
I need to use .NET 7.0 and on that platform:
108.0.3 has a bug and throws an exception explained here: https://github.com/restsharp/RestSharp/issues/1969
109.0.1 doesn't work with the above issue.
If someone gives me a solution/workaround I'll happily contribute $50 for this project, because currently I can't do my work as nothing works since the .NET 7.0 upgrade.
The text was updated successfully, but these errors were encountered: