【发布时间】:2019-07-07 05:02:06
【问题描述】:
我正在调用我的 laravel 控制器中的一个函数。我已经使用 laravel 的自定义响应来返回数据。但即使我没有添加一些其他数据,也会添加到我的回复中。
return Response::make(json_encode(array(
'error' => false,
'message' => 'Redaction done successfully.',
'is_redacted' => 0)), 200,
array(
'Content-Type' => 'application/json'
)
);
以上是我添加的用于返回响应的代码。 但我收到的回复是:
> * Found bundle for host redaction-stage-tcm.tylerhost.net: 0x55998c67ee40
* Re-using existing connection! (#0) with host redaction-stage-tcm.tylerhost.net
* Connected to redaction-stage-tcm.tylerhost.net (208.64.239.110) port 443 (#0)
> POST /ocr/OCRWeb/v2/Documents('mfr_8')/OCRWeb.Scan HTTP/1.1
Host: redaction-stage-tcm.tylerhost.net
User-Agent: GuzzleHttp/6.3.3 curl/7.43.0 PHP/5.6.11-1ubuntu3.4
OData-Version: 4.01
OData-MaxVersion: 4.01
Content-Type: application/json
Content-Length: 2
upload completely sent off: 2 out of 2 bytes
< HTTP/1.1 200
< Cache-Control: no-transform
< Cache-Control: no-cache
< Cache-Control: no-store
< Cache-Control: must-revalidate
< Cache-Control: max-age=0
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Vary: *
< Pragma: no-cache
< X-Clacks-Overhead: GNU Terry Pratchett
< OData-Version: 4.01
< Preference-Applied:
< Content-Type: application/json; odata.metadata=minimal
< Content-Length: 163
< Date: Wed, 13 Feb 2019 10:44:40 GMT
<
* Connection #0 to host redaction-stage-tcm.tylerhost.net left intact
{"error":false,"message":"Redaction done successfully.","is_redacted":0}
我在我的函数中调用了一些其他 API。此数据与此相关,但为什么它会附加到我的自定义响应中? 请帮帮我。
【问题讨论】:
-
那你到底想返回什么?而且我不确定,只是猜测,您使用的
Response外观一定属于其他命名空间,而不是 Laravel (Illuminate\Http\Response)。 -
我错过了什么吗?内容看起来不错。如果您对默认标头感到困扰,请注意您使用代码附加自定义标头而不是替换默认标头。