问题
From my custom Wordpress rest api, i need to return below text as content type html.
OK
ImageSendURL=www.yourdomain.xxx/Plugin/DownloadOrders
Here is my code to return the same
return new WP_REST_Response( "OK \n URL={$options['url']}", 200, array('content-type' => 'text/html; charset=utf-8'));
But this returns
"OK \n URL=http:\/\/yourdomain.xxx\/Plugin\/DownloadOrders"
I don't want the leading and trailing double quotes " and also the URL is kind screwed up. how can i fix this?
with the below code:
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""
now not sure how to get rid of the trailing ""
回答1:
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)
Don't do 'return', just do
header('Content-Type: text/html')
echo '<your html here>';
exit();
the exit function don't let the Wordpress to use WP_HTTP_Response class
来源:https://stackoverflow.com/questions/49365576/wordpress-rest-api-response-sending-html-content-type-issue-with-forward-slash-i