C# HttpClient PostAsync turns 204 into 404

后端 未结 2 1519
生来不讨喜
生来不讨喜 2021-02-08 04:00

Given this WebApi service:

[ActionName(\"KillPerson\")]
[HttpPost]
public void KillPerson([FromBody] long id)
{
    // Kill
}

And this HttpClie

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-08 04:24

    Finally figured this out. Seems you get a choice of using either browser or client HTTP handling in Silverlight. When using browser HTTP handling a lot of stuff is unsupported - including various response codes and headers. Adding these lines before calling HttpClient fixed it:

    WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
    WebRequest.RegisterPrefix("https://", WebRequestCreator.ClientHttp);
    

提交回复
热议问题