我试图通过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