简体   繁体   English

标头或内容中的Http响应状态

[英]Http response status in headers or in content

I have to write an application which serves HTTP request . 我必须编写一个服务于HTTP request的应用程序。 For these requests application has to send the response content with status**. 对于这些请求,应用程序必须发送状态为**的响应内容。 Status is integer which represents status code.( 1 : Session Expired, 2: Invalid Request Data. etc,.) 状态是代表状态代码的整数。(1:会话已过期,2:无效的请求数据等。)

There are 2 options. 有2个选项。

One is to send the status code with content itself: 一种是发送状态代码和内容本身:

Ex : {status : 56, content: [{name:'pinto', id: 90}]} 例如: {status : 56, content: [{name:'pinto', id: 90}]}

Another one is specifying the status code in header itself, so that once I receive the header from client if status states the there is an error I can abort the request so that I don't have to receive the response body and process it. 另一个是在标头本身中指定状态代码,这样,一旦我从客户端接收到标头(如果状态表明存在错误),我就可以中止请求,这样我就不必接收响应主体并对其进行处理。

I think second option will be better than first one, because No need to get for the response content which is very much helpful in case of content is large. 我认为第二种选择会比第一种更好,因为不需要获取响应内容,这在内容很大的情况下非常有帮助。

Is this is recommended solution or any other suggestions ? 这是推荐的解决方案还是其他建议?

You should be using HTTP status codes for this kind of thing. 您应该将HTTP状态代码用于此类操作。

  1. Session Expired: 401 Unauthorized - authentication is possible but has failed 会话已过期: 401未经授权 -可以进行身份​​验证但失败
  2. Invalid Request Data: 无效的请求数据:

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

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