我可以使用一些帮助,因为我已经被困 2 天了。我用谷歌搜索,但找不到正确的解决方案。
任何人都可以帮助解决如何修复或如何更好地调试吗?
发送到本地主机的内容
POST /Service1.svc/addt HTTP/1.1
Content-Type: application/json
Host: localhost.:13309
Content-Length: 25
Expect: 100-continue
Connection: Keep-Alive
响应(使用提琴手查看)
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Invalid Hostname</h2>
<hr><p>HTTP Error 400. The request hostname is invalid.</p>
</BODY></HTML>
GET 操作运行正常,所以我觉得确实是 POST 操作出错了。
有关 Web.config 和 Post 操作下方的信息
string requestData = "{\"ID\":1,\"Make\":\"Ferrari\"}";
byte[] data = Encoding.UTF8.GetBytes(requestData);
request = (HttpWebRequest)WebRequest.Create("http://localhost.:13309/Service1.svc/addt");
request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = data.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(data, 0, data.Length);
dataStream.Close();
WebResponse webr = request.GetResponse();
<system.web>
<compilation debug="true" targetFramework="4.5" />
<customErrors mode="Off"/>
<httpRuntime requestPathInvalidCharacters="<,>,*,%,:,\,?" maxRequestLength="2097151" />
</system.web>
<system.serviceModel>
<services>
<service name="FinanceService.Service1" behaviorConfiguration="ServiceBehaviour">
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address ="" binding="webHttpBinding" contract="FinanceService.IService1" behaviorConfiguration="web">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>