wordpress rest api 响应在 URL 中发送带有正斜杠的 html 内容类型问题 [英] wordpress rest api response sending html content type issue with forward slash in URL

查看:22
本文介绍了wordpress rest api 响应在 URL 中发送带有正斜杠的 html 内容类型问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

From my custom Wordpress rest api, i need to return below text as content type html.

好的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 也搞砸了.我该如何解决这个问题?

I don't want the leading and trailing double quotes " and also the URL is kind screwed up. how can i fix this?

使用以下代码:

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

我得到了

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

现在不知道如何去掉尾随的"

now not sure how to get rid of the trailing ""

推荐答案

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

the quotes are there because it's using the WP_HTTP_Response class that trying to give you a json as a response (uses the json_encode() function)

不做'return',只做

Don't do 'return', just do

header('Content-Type: text/html')
echo '<your html here>';
exit();

退出函数不让 Wordpress 使用 WP_HTTP_Response 类

the exit function don't let the Wordpress to use WP_HTTP_Response class

这篇关于wordpress rest api 响应在 URL 中发送带有正斜杠的 html 内容类型问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆