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
最满意答案
在实际考虑通过我自己的手腕咀嚼和整夜梦见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传递客户端IP以验证程序?(How to configure squid to pass client ip to authenticate program?)[2023-11-02]
似乎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 ...
-
Squid路由SSL流量(Squid routing SSL traffic)[2023-06-26]
您正在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 Squid代理连接到Parent Bluecoat w Auth(Connect pfsense Squid Proxy to Parent Bluecoat w Auth)[2023-07-31]
我从来没有找到解决方案。 我最终将主机连接到两个网络,一个是企业防火墙,另一个是没有,然后使用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....)
-
Squid代理access_log(Squid Proxy access_log)[2024-03-15]
您需要弄清楚为什么系统设置的日期不正确,并且已经解决了这个问题,以缓解问题。 对于像2002这样的日期,我将猜测服务器硬件上的死BIOS电池。 对于稍微不准确的时间,一种可能的缓解是使用NTP将时间与良好时间源同步。 如果使用虚拟化技术,您需要小心在理想层使用NTP。 通常,您希望在尽可能低的层(例如虚拟化软件)上同步时间,以确保最高的一致性和最佳性能。 因此,如果您使用的是虚拟化软件,请查看是否可以将其配置为将时间与网络时间服务器同步。 否则,请考虑为您选择的平台设置NTP客户端。 You need to ... -
Squid代理返回HTTP与HTTPS的不同错误消息(Squid Proxy Returns Different Error Messages For HTTP vs. HTTPS)[2024-02-10]
我偶然发现了这个问题的答案。 当我将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 ...