首页 \ 问答 \ cURL响应HTML以纯文本形式而不是呈现的HTML回显(cURL response HTML is echoed as plain text instead of rendered HTML)

cURL响应HTML以纯文本形式而不是呈现的HTML回显(cURL response HTML is echoed as plain text instead of rendered HTML)

我正在发布一个使用PHP curl返回HTML的API端点。 当我回显响应时,它以纯文本形式打印,而不是以HTML格式呈现。

标题是正确的,因为如果我回显一串HTML,它会正常呈现。

有关如何使其渲染的任何想法?

$url = 'https://inlinestyler.torchbox.com/styler/convert/';
$myvars = 'source_url=XXXXXXXXXX&returnraw=1';

$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

$content = curl_exec( $ch );

// Plaintext
echo $content;

// Shows HTML
echo '<h1>Testing</h1>';

I'm POST-ing to an API endpoint that returns HTML using PHP curl. When I echo the response, it prints as plain text instead of rendering as HTML.

The headers are correct because if I echo a string of HTML, it renders normally.

Any ideas on how to make it render instead?

$url = 'https://inlinestyler.torchbox.com/styler/convert/';
$myvars = 'source_url=XXXXXXXXXX&returnraw=1';

$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

$content = curl_exec( $ch );

// Plaintext
echo $content;

// Shows HTML
echo '<h1>Testing</h1>';

原文:https://stackoverflow.com/questions/37308973
更新时间:2021-08-14 10:08

最满意答案

在实际考虑通过我自己的手腕咀嚼和整夜梦见IPs之后+蛮力搜索/尝试任何我可以得到我的数字手指,我设法把实际上工作的东西放在一起。 我不知道技术上的原因,所以如果你能提供设置解释,请这样做! :d

PS:解释中的所有内容都是通过命令行完成的

PS:这不是最终的解决方案,但它是回答我自己的问题的工作方案。

这里是:

步骤1:必须在框上启用IP转发:

vim /etc/sysctl.conf

//找到并取消注释以下内容

net.ipv4.ip_forward=1
net.ipv4.conf.all.rp_filter=1

第2步:添加循环返回规则(这更适用于涵盖所有端口的情况,显然许多应用程序都需要它?

iptables -I INPUT -i lo -j ACCEPT

第3步。为旁路端口443添加规则:(eth1是Internet接口,xxxx / eth0是LAN接口)

iptables -t filter -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT

iptables -t filter -A FORWARD -i eth0 -p tcp --dport 443 -j ACCEPT

iptables -t nat -A POSTROUTING -o eth1 -j SNAT --to-source x.x.x.x

第4步。最后,使Squid透明的规则:(xxxx是LAN接口的IP)

iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j DNAT --to-destination x.x.x.x:3128

iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128

After actually considering chewing through my own wrists and dreaming of IPs all night long + brute force googling/trying ANYTHING i could get my digital fingers on i managed to put something together that actually works. I dont know the technical reasons why, so if you can provide set explanations please do so! :D

PS: everything in the explanation is done via command line

PS: this is not a final solution, but its a working one in answer to my own question.

Here it is:

Step 1: Had to enable IP Forwarding on the box:

vim /etc/sysctl.conf

//find and uncomment the following

net.ipv4.ip_forward=1
net.ipv4.conf.all.rp_filter=1

Step 2: Add loop back rule (this is more for when all ports are covered, apparently many apps need it?

iptables -I INPUT -i lo -j ACCEPT

Step 3. Add rules for the bypassing of port 443: (eth1 is internet interface and x.x.x.x/eth0 is LAN interface)

iptables -t filter -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT

iptables -t filter -A FORWARD -i eth0 -p tcp --dport 443 -j ACCEPT

iptables -t nat -A POSTROUTING -o eth1 -j SNAT --to-source x.x.x.x

Step 4. Then finally the rules making Squid transparent:(x.x.x.x is IP of LAN interface)

iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j DNAT --to-destination x.x.x.x:3128

iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128

相关问答

更多
  • 使用URL_REGEX 。 只有在Windows中对我有用。 Use URL_REGEX. Only that worked for me in Windows.
  • 在nginx中: proxy_pass http://@squid; 在鱿鱼: http_port 3128 vhost 这就是修复此https://imgur.com/qtgrZI9错误所需的全部内容 in nginx: proxy_pass http://@squid; in squid: http_port 3128 vhost and that's all you need for fix this https://imgur.com/qtgrZI9 error
  • 似乎Squid 3.5将添加这个新功能:auth_param的key_extras。 http://www.squid-cache.org/Doc/config/auth_param/ http://devel.squid-cache.org/customlog/logformat.html %la:接受请求的本地IP地址 然后我们可以将“本地IP地址”添加到身份验证程序命令行,如下所示:auth_param digest key_extras“%la” It seems Squid 3.5 will ad ...
  • 在实际考虑通过我自己的手腕咀嚼和整夜梦见IPs之后+蛮力搜索/尝试任何我可以得到我的数字手指,我设法把实际上工作的东西放在一起。 我不知道技术上的原因,所以如果你能提供设置解释,请这样做! :d PS:解释中的所有内容都是通过命令行完成的 PS:这不是最终的解决方案,但它是回答我自己的问题的工作方案。 这里是: 步骤1:必须在框上启用IP转发: vim /etc/sysctl.conf //找到并取消注释以下内容 net.ipv4.ip_forward=1 net.ipv4.conf.all.rp_fil ...
  • 您正在DNATing进入代理的数据包。 但是,您是否正在对从代理服务器返回的数据包进行扫描? You are DNATing packets going to the proxy. But are you SNATing the packets coming back from the proxy ?
  • 据我了解您的问题,流量是在本地生成的。 因此,数据包不会遍历PREROUTING链。 您必须处理OUTPUT或POSTROUTING: iptables -t nat -A OUTPUT -p tcp -o lo --dport 80 -j DNAT --to publicip:3128 另外,请务必以透明代理模式设置Squid: httpd_accel_host virtual httpd_accel_port 80 httpd_accel_with_proxy on httpd_accel_uses_ ...
  • 我从来没有找到解决方案。 我最终将主机连接到两个网络,一个是企业防火墙,另一个是没有,然后使用PFSense路由器连接到两个网络的两个虚拟网络。 I never found a solution for this. I ended up connecting the host to two networks, one Corporate Firewalled and one not, then used PFSense Router with two virtual nics connected to th ...
  • 我发现它:在IE11中禁用SPDY / 3 Protokol(附加......) I found it: Disable SPDY/3 Protokol in IE11 (Extras....)
  • 您需要弄清楚为什么系统设置的日期不正确,并且已经解决了这个问题,以缓解问题。 对于像2002这样的日期,我将猜测服务器硬件上的死BIOS电池。 对于稍微不准确的时间,一种可能的缓解是使用NTP将时间与良好时间源同步。 如果使用虚拟化技术,您需要小心在理想层使用NTP。 通常,您希望在尽可能低的层(例如虚拟化软件)上同步时间,以确保最高的一致性和最佳性能。 因此,如果您使用的是虚拟化软件,请查看是否可以将其配置为将时间与网络时间服务器同步。 否则,请考虑为您选择的平台设置NTP客户端。 You need to ...
  • 我偶然发现了这个问题的答案。 当我将WampServer 2.2E开发环境中的PHP从5.3.13升级到5.4.45时,我发现PHP 5.4.45没有返回http response code said error消息。 它不会返回任何内容,这是我预计在涉及HTTPS错误时会发生的事情。 错误消息由PHP 5.3.13生成,但不是PHP 5.4.45。 I found the answer to this question quite by accident. When I upgraded the PHP ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)