返回具有 HTTP 状态错误的自定义正文



我有一个奇怪的问题,我正在两个不同的服务器上进行测试,

  • 第一台具有基本 Apache 的服务器
  • 带有 Zend 服务器的第二台服务器

我正在尝试做的是使用 cURL 调用该服务器上的 url,该 url 可以返回以下代码之一:200406,带有包含消息的 json 正文。

查询 Apache 服务器时,在 406 错误上,我得到这个:

< HTTP/1.1 100 Continue
< HTTP/1.1 406 Not Acceptable
< Date: Wed, 10 Dec 2014 11:16:01 GMT
< Server: Apache/2.4.10 (Ubuntu)
< Content-Length: 75
< Content-Type: application/json
* HTTP error before end of send, stop sending
<
{"status":406,"message":"Domain not found (is the file named correctly ?)"}* Closing connection 0

在查询Zend服务器时,我得到这个:

< HTTP/1.1 100 Continue
< HTTP/1.1 406 Not Acceptable
< Date: Wed, 10 Dec 2014 11:15:05 GMT
< Connection: Keep-Alive
< Content-Type: text/html; charset=iso-8859-1
< Content-Length: 261
* HTTP error before end of send, stop sending
<
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>406 Not Acceptable</title>
</head><body>
<h1>Not Acceptable</h1>
<p>An appropriate representation of the requested resource /webservice could not be found on this server.</p>
</body></html>
* Closing connection #0
* SSLv3, TLS alert, Client hello (1):

标头类型从应用程序/json 更改为 text/html,正文是纯 html 错误页面。

这是 Zend 服务器问题吗?

我认为这两者都不是问题。两个服务器返回的错误代码都是 406,但 http 响应正文中的错误消息在 apache 中以 json 的形式发送,在 zend 服务器中以 html 的形式发送,因此内容类型不同。

两台服务器选择以不同的格式发送错误消息,因此内容类型不同。

最新更新