StatusCode:404,ReasonPhrase:从C#调用web api时'找不到'

时间:2014-09-07 14:28:21

标签: c# asp.net-web-api

当我在localhost上托管它并尝试调用它时它使用webapi它工作正常但是当我将它托管到域服务器时它会返回:"StatusCode: 404, ReasonPhrase: 'Not Found'"

client.BaseAddress = new Uri("http://xyz.website.com/API");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.GetAsync("api/Store").Result;

但结果是:

{StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
  Connection: Keep-Alive
  Date: Sun, 07 Sep 2014 14:19:28 GMT
  Server: Microsoft-IIS/8.0
  X-Powered-By: ASP.NET
  Content-Length: 1245
  Content-Type: text/html
}}

我认为在website.com

之前,前缀名称('xyz')存在问题

1 个答案:

答案 0 :(得分:0)

有时将此方法放入您的方法中也可以。刚刚遇到同样的问题并使用下面提到的方法解决了它。

WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultCredentials;