Curl添加反斜杠 [英] Curl add backslashes

查看:536
本文介绍了Curl添加反斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试传递数组到curl参数,但curl在请求中添加反斜杠。



PHP代码:
$ b

  $ domain ='website.com'; 
curl_setopt($ ch,CURLOPT_URL,http://domain.com/x.json?domains='[\\"\"$$domain.\"\]');

日志

 GET /x.json?domains='[\\"http://website.com\]'HTTP / 1.1200 105 -  - 

正如你看到的数组看起来像'[\http: //website.com\]'不是'[http://website.com]'



有人可以帮助我。

解决方案

您可以使用 urlencode() 将值作为GET参数传递

  curl_setopt($ ch, CURLOPT_URL,http://website.com/x.json?domains=.urlencode('['。$ domain。']')); 


I tried to pass array to curl parameters but curl add backslashes to the request.

Php code :

$domain = 'website.com';
curl_setopt($ch, CURLOPT_URL, "http://domain.com/x.json?domains='[\"".$domain."\"]'");

The logs :

"GET /x.json?domains='[\"http://website.com\"]' HTTP/1.1" 200 105 "-" "-"

As you see the array look like '[\"http://website.com\"]' not '["http://website.com"]'.

Can someone help me please.

解决方案

You can use urlencode() to pass a value as GET parameter with an url.

Try:

curl_setopt($ch, CURLOPT_URL, "http://website.com/x.json?domains=".urlencode( '["'.$domain.'"]' ) );

这篇关于Curl添加反斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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