Skip to content
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

POST with no data doesn't work #4

Open
DanielSundberg opened this issue Dec 2, 2016 · 2 comments
Open

POST with no data doesn't work #4

DanielSundberg opened this issue Dec 2, 2016 · 2 comments

Comments

@DanielSundberg
Copy link

DanielSundberg commented Dec 2, 2016

I have the following API-method:

[Route("api/xyz")]
[HttpPost]
public IHttpActionResult PostAPIXYZ() {
    return Ok("ok");
}

Then calling it with:

using PainlessHttp.Http;

var config = new Configuration {
     BaseUrl = "http://localhost:81",
};

HttpClient = new HttpClient(config);    
var result = HttpClient.PostAsync<MyResult>("api/xyz", null).Result;

Result: Http status: LengthRequired (411)

In powershell it works ok:

> (Invoke-WebRequest http://localhost:81/api/xyz -Method POST).StatusDescription
OK

Using Http client from System.Net.Http works ok:

using System.Net.Http;

HttpClient HttpClient = new HttpClient {
    BaseAddress = new Uri(http://localhost:81), 
};
var result = HttpClient.PostAsync("api/xyz", new StringContent(""))
@pardahlman
Copy link
Owner

Hi @DanielSundberg,
Thanks for reporting this. PainlessHttp has not been updated for some time, one reason is that it's based on HttpRequester, which is discontinued in dotnet core.

Anyways, I believe that the problem is that you're in fact sending a POST body, the (empty) StringContent. It will eventually get serialized. You could try string.Empty or try the method PerformRaw that does not require you to specify any body.

Hope this helps!

@DanielSundberg
Copy link
Author

DanielSundberg commented Dec 5, 2016

string.Empty doesn't work.

HttpClient.PerformRawAsync(HttpMethod.Post, "api/xyz") with no data still gives me Http status LengthRequired.

Using System.Net.Http.HttpClient for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants