简体   繁体   中英

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. I have my own logs but I want to try to make it obvious in IIS logs as well.

Currently the IIS logs a status 200 for all responses. 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). 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.

Thanks.

Why are you sending HTTP status codes and not your own application status codes?

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. Your XML is merely data as far as IIS is concerned, unless you have a special handler or filter or something installed. Otherwise IIS will only concern itself with the values of your HTTP response headers.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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