私はHTTPメソッドを介して、次のWebAPIのコントローラメソッドにアクセスしようとしているHttpClientを介して、オブジェクトを送る
[System.Web.Http.Route("api/Users/Signin")]
[ResponseType(typeof(bool))]
public bool UserSingIn(User obj)
{
bool isuserexit = _usersRepo.UserSignIn(obj);
if (isuserexit == true)
{
return true;
}
return false;
}
これは私がUser obj
オブジェクトを送信使用しようとしているHTTPメソッドで、
private string USER_URL = "http://localhost:3623/api/Users";
public bool GetUser(User obj)
{
try
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(USER_URL);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.PutAsJsonAsync("Users/Signin", obj).Result;
if (response.IsSuccessStatusCode)
return response.Content.ReadAsAsync<bool>().Result;
return false;
}
catch
{
return false;
}
}
しかし、これはで終わるresponse : {StatusCode: 405, ReasonPhrase: 'Method Not Allowed', ..}
あなたのURLに '/ Signin'を追加する必要があると思います。 –
GETエンドポイントにHTTP PUTリクエストを作成しています。 –
@ChrisPickford私は '' [HttpPut] 'を実行してから' '内部サーバーエラー" ' – kez