[英]WebAPI - works local but receive 404 error on remote server
这工作...
client.BaseAddress = new Uri("http://localhost/InventoryApi/");
这失败了...
client.BaseAddress = new Uri("http://yyyZLtd.com/");
在 Win Server 2012 R2 上运行 IIS 8.5 的远程服务器
完整代码...
client.BaseAddress = new Uri("http://localhost/InventoryApi/");
或者
client.BaseAddress = new Uri("http://yyyZLtd.com/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync("api/Inventory/99");
if (response.IsSuccessStatusCode) <- ERROR RETURNED
完整的错误信息...
{StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Date: Mon, 02 May 2016 14:54:08 GMT Server: Microsoft-IIS/8.5 X -Powered-By: ASP.NET Content-Length: 1245 Content-Type: text/html }}
我肯定错过了什么。 Web Api 的新成员,一直使用 SOAP,这似乎更容易。
谢谢,任何帮助表示赞赏。
就在我准备戒烟的时候……我之前尝试过没有成功,但这次成功了……
德鲁……谢谢你的建议。
我完全重新开始 - 第 4 次尝试成功。 最初,我试图从空模板创建一个 WebApi 项目并且只添加 WebApi。 我最终决定使用 Mvc 和 WebApi 以及 4.6 的目标框架使用空模板。 我添加了与之前使用的相同的类和控制器,并且它起作用了,至少在 Get 或 Post 上。 上面的模块更改,给了我放置和删除的能力。
我对我的 Web.Config 进行了以下更改...
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule" />
</modules>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<remove name="WebDAV"/>
<remove name="OPTIONSVerbHandler"/>
<remove name="TRACEVerbHandler"/>
<remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*,GET,POST,PUT,DELETE" type="System.Web.Handlers.TransferRequestHandler"
preCondition="integratedMode,runtimeVersionv4.0"/>
</handlers>
希望这对其他人有所帮助。 在让一切正常工作之前,我断断续续地玩了 4 天。 如果有人愿意,非常乐意分享代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.