简体   繁体   English

具有有效xml字符串响应的Http状态代码

[英]Http status code with a valid xml string response

I am trying to determine the right status code to apply where the response is not empty. 我正在尝试确定正确的状态码,以在响应不为空的情况下应用。

When a user requests a file and the file does not exist in the server. 当用户请求文件而服务器中不存在该文件时。 The user is returned an error message in xml format. 向用户返回xml格式的错误消息。 I have my own logs but I want to try to make it obvious in IIS logs as well. 我有自己的日志,但是我也想尝试使其在IIS日志中也很明显。

Currently the IIS logs a status 200 for all responses. 当前,IIS为所有响应记录状态200。 But I want to set a different status code is the server does not find the file. 但是我要设置一个不同的状态代码是服务器找不到文件。

The problem is during unit testing I found the response is empty if the status code is not 200. I have tried (410, 206, 204). 问题是在单元测试期间,我发现如果状态码不是200,则响应为空。我已经尝试过(410、206、204)。 So the client does not receive the error message. 因此,客户端不会收到错误消息。

Just want to know if there is any status code I can set and also send the error message. 只想知道我是否可以设置任何状态代码,并发送错误消息。

I am using C# ASP.NET Web Service. 我正在使用C#ASP.NET Web服务。

Thanks. 谢谢。

Why are you sending HTTP status codes and not your own application status codes? 为什么要发送HTTP状态代码而不发送自己的应用程序状态代码?

IIS logs will never record the code that you return in XML, it will only log the status code it receives from the server that serves your web service. IIS日志永远不会记录您以XML返回的代码,它只会记录从服务您的Web服务的服务器接收到的状态代码。 Your XML is merely data as far as IIS is concerned, unless you have a special handler or filter or something installed. 就IIS而言,您的XML仅仅是数据,除非您安装了特殊的处理程序或过滤器或其他东西。 Otherwise IIS will only concern itself with the values of your HTTP response headers. 否则,IIS将只与HTTP响应标头的值有关。

EDIT: 编辑:
When you set HTTP Status Codes manaully the server will still act within the guidelines of the HTTP spec which states that only a 200 will be accompanied by a full response body. 当您手动设置HTTP状态代码时,服务器仍将在HTTP规范的指导下工作,该规范指出仅200会带有完整的响应正文。

HTTP / 1.1 404(未找到)是合适的-大多数服务器都允许您返回内容,因为通常您希望返回用户可读的HTML页面以表明您实际上未点击真实页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM