我試圖通過HTTP的方法來訪問下面的WebAPI控制器的方法發送對象
[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;
}
這是HTTP方法我試圖用送User obj
對象,
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