FubarDevelopment / restsharp.portable

Some kind of a RestSharp port to PCL
BSD 2-Clause "Simplified" License
96 stars 33 forks source link

PUT/POST form content is not quite right #69

Closed jchannon closed 8 years ago

jchannon commented 8 years ago

Hi,

We've spotted something odd when using the below code:

 var client = new RestClient("http://localhost:1234"); 
 client.IgnoreResponseStatusCode = true;
 client.Timeout = TimeSpan.FromSeconds(1);
 var req = new RestRequest("/body", Method.PUT);
 req.AddHeader("Content-Type","application/x-www-form-urlencoded");
 req.AddParameter("name","john", ParameterType.RequestBody);
 var res = client.Execute(req).Result;

In the screenshot you'll see that the form looks like "john=john" and the raw body is "john".

Using Postman the Form and Body is "name=john" as expected

screen shot 2016-05-20 at 20 27 13

fubar-coder commented 8 years ago

You have to use GetOrPost as parameter type.

fubar-coder commented 8 years ago

And you have to use POST. Using PUT does seem unusual for form-url-encoded

jchannon commented 8 years ago

Ah I've spotted it. Using GetOrPost on a PUT it doesn't add the ContentType header

jchannon commented 8 years ago

Using PUT and RequestBody it defaults to application/json

jchannon commented 8 years ago

Seems that it should add the header of application/x-www-form-urlencoded like it does for POST when using PUT when using GetOrPost

fubar-coder commented 8 years ago

It's some kind of tough. application/x-www-form-urlencoded is very unusual for PUT requests, because those are usually for storing data (see What's the difference between a POST and a PUT HTTP REQUEST?). I agree, that there should be a way to support application/x-www-form-urlencoded together with PUT. Please let me validate some things first.

jchannon commented 8 years ago

Ok thanks.

I'll check with a colleague but I think they are using PUT on a 3rd party API that has this requirement.

If it helps Restsharp seems to work. They spotted it when it didn't work the same with Portable

On Friday, 20 May 2016, Mark Junker notifications@github.com wrote:

It's some kind of tough. application/x-www-form-urlencoded is very unusual for PUT requests, because those are usually for storing data (see What's the difference between a POST and a PUT HTTP REQUEST? http://stackoverflow.com/questions/107390/whats-the-difference-between-a-post-and-a-put-http-request). I agree, that there should be a way to support application/x-www-form-urlencoded together with PUT. Please let me validate some things first.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/FubarDevelopment/restsharp.portable/issues/69#issuecomment-220703253

fubar-coder commented 8 years ago

I released a new alpha version. Please close this issue when the request works as expected.

jchannon commented 8 years ago

Where can I see it?

On 20 May 2016 at 22:32, Mark Junker notifications@github.com wrote:

I released a new alpha version. Please close this issue when the request works as expected.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/FubarDevelopment/restsharp.portable/issues/69#issuecomment-220723669

fubar-coder commented 8 years ago

You can find the nuget feed on the myget gallery page: https://www.myget.org/gallery/restsharp-portable

jchannon commented 8 years ago

Thanks

On Saturday, 21 May 2016, Mark Junker notifications@github.com wrote:

You can find the nuget feed on the myget gallery page: https://www.myget.org/gallery/restsharp-portable

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/FubarDevelopment/restsharp.portable/issues/69#issuecomment-220767358

jchannon commented 8 years ago

I get an error when adding it 'FubarCoder.RestSharp.Portable.Core' already has a dependency defined for 'NETStandard.Library'.

On 21 May 2016 at 10:25, Jonathan Channon jonathan.channon@gmail.com wrote:

Thanks

On Saturday, 21 May 2016, Mark Junker notifications@github.com wrote:

You can find the nuget feed on the myget gallery page: https://www.myget.org/gallery/restsharp-portable

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/FubarDevelopment/restsharp.portable/issues/69#issuecomment-220767358

fubar-coder commented 8 years ago

It's a known problem. You have to use NuGet 3.5 beta (also for Visual Studio 2015 as VSIX). You can download it from https://dot.net download section

jchannon commented 8 years ago

Updated but now it doesn't compile: capture

Is there a DLL naming issue? The packages.config says FubarCoder.RestSharp.Portable.Core but the References says RestSharp.Portable.Core For HTTPClient they say both the same prefixed with FubarCoder

fubar-coder commented 8 years ago

This works here. It seems that you forgot a dotnet restore (when using .NET Core), or maybe nuget didn't add the FubarCoder.RestSharp.Portable.Core to your project and/or packages.config.

Example application (using both .NET Core and .NET Framework 4.6.1) TestRestSharpPortableCore.zip

jchannon commented 8 years ago

Looks like nuget messed it up, re-added the reference and now works as expected with PUT and GetOrPost