ASP.NET Web API を使用し、http://stevescodingblog.co.uk/basic-authentication-with-asp-net-webapi/を参照して認証を使用します。
Authorizationヘッダを持たないリクエストの場合、レスポンスのHttpStatusCodeは「Unauthorized」になります。
ただし、いくつかの json データがクライアント側から送信され、いくつかの列が正しくない場合、リクエストに Authorization ヘッダーがありませんが、応答 HttpStatusCode は「Internal Server Error」になります。
[BasicAuthentication]
public HttpResponseMessage Create(Customer customer)
{
//
}
public class Customer{
public int id{set;get;}
public string name{set;get;}
}
たとえば、POST メソッドを /Create に送信し、Content-Type が application/json で、Request Body { "id": "abc", "name": "someone" }(id is wrong:not int but string) と don を送信します。 Authorization ヘッダーがありません。応答 HttpStatusCode は、「Unauthorized」ではなく「Internal Server Error」です。
顧客インスタンスの作成は、承認よりも前に行われている可能性があります。最初に承認を変更することを知っていますか?