Skip to content

POST with no data doesn't work #4

@DanielSundberg

Description

@DanielSundberg

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(""))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions