我在我的 Web API 上使用HttpResponseMessage,因为它大大简化了事情。我遇到的问题是,在 IIS Express 下运行的 VS 2017 中测试代码时,我的代码执行没有问题,但是当我从 Postman 进行测试时,我完全没有得到任何响应。我想知道它是否与标题和/或配置有关。这是 Postman 发回的内容:
无法得到任何响应连接到http://localhost:12345/Url/RequestUrl时出错。
这是正在运行的代码的一部分:
[OperationContract]
[ADAuthorize(Action = "RequestUrl", Controller = "Url")]
[HttpPost]
public HttpResponseMessage RequestUrl(Stream inputServiceRequestParameters)
{
Request = new HttpRequestMessage();
Configuration = new HttpConfiguration();
try
{
// Retrieve and place JSON parameters into object.
var serviceRequestParameters = JsonFunctions.GetServiceRequestParameters(inputServiceRequestParameters);
// Retrieve member GUID from LDAP.
var contactId = LdapFunctions.GetMemberCrmGuid(serviceRequestParameters.MemberNumber);
// Member information not found in LDAP, so return without processing.
if (contactId == null)
{
var response = Request.CreateResponse(HttpStatusCode.InternalServerError,
JsonFunctions.BuildErrorResponse("", Constants.ValidationMessage.MEMBER_NOT_IN_LDAP));
response.Content = new StringContent(JsonFunctions.BuildErrorResponse("", Constants.ValidationMessage.MEMBER_NOT_IN_LDAP));
response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
return response;
}
[在此之后继续上课……]
所有这些代码运行良好,但没有返回任何内容。甚至 Fiddler 也抱怨ReadResponse() failed。
我看过大量的例子,但我仍然无法弄清楚发生了什么,我错过了什么。