当我在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')存在问题答案 0 :(得分:0)
有时将此方法放入您的方法中也可以。刚刚遇到同样的问题并使用下面提到的方法解决了它。
WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultCredentials;