从我的自定义 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'));
但这返回
"OK \n URL=http:\/\/yourdomain.xxx\/Plugin\/DownloadOrders"
我不想要前导和尾随双引号 " 并且 URL 也搞砸了。我该如何解决这个问题?
使用以下代码:
echo "OK \n ImageSendURL={$options['url']}";
return new WP_REST_Response( "", 200, array('content-type' => 'text/html; charset=utf-8'));
i got
OK ImageSendURL=http://yourdomain.xxx/Plugin/DownloadOrders""
现在不知道如何摆脱尾随的“”
引号在那里是因为它使用 WP_HTTP_Response 类,试图给你一个 json 作为响应(使用json_encode()
功能)
不做“返回”,只做
header('Content-Type: text/html')
echo '<your html here>';
exit();
exit 函数不允许 WordPress 使用 WP_HTTP_Response 类
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)