wordpress rest api 响应在 URL 中发送带有正斜杠的 html 内容类型问题

Sum*_*P89 2 wordpress

从我的自定义 Wordpress rest api,我需要将下面的文本作为内容类型 html 返回。

OK ImageSendURL=www.yourdomain.xxx/Plugin/DownloadOrders

这是我返回相同的代码

return new WP_REST_Response( "OK  \n  URL={$options['url']}", 200, array('content-type' => 'text/html; charset=utf-8'));
Run Code Online (Sandbox Code Playgroud)

但这返回

"OK  \n  URL=http:\/\/yourdomain.xxx\/Plugin\/DownloadOrders"
Run Code Online (Sandbox Code Playgroud)

我不想要前导和尾随双引号 " 并且 URL 也搞砸了。我该如何解决这个问题?

使用以下代码:

echo "OK  \n  ImageSendURL={$options['url']}";
return new WP_REST_Response( "", 200, array('content-type' => 'text/html; charset=utf-8'));
Run Code Online (Sandbox Code Playgroud)

我有

OK ImageSendURL=http://yourdomain.xxx/Plugin/DownloadOrders""

现在不知道如何摆脱尾随的“”

小智 6

引号在那里是因为它使用 WP_HTTP_Response 类试图给你一个 json 作为响应(使用json_encode()函数)

不要做“返回”,只要做

header('Content-Type: text/html')
echo '<your html here>';
exit();
Run Code Online (Sandbox Code Playgroud)

退出函数不让 Wordpress 使用 WP_HTTP_Response 类