php
  • arrays
  • curl
  • 2016-03-22 83 views 1 likes 
    1

    我试图传递数组来卷曲参数,但是卷曲会在请求中添加反斜杠。卷曲添加反斜杠

    PHP代码:

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

    日志:

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

    正如你所看到的阵列看起来像'[\"http://website.com\"]''["http://website.com"]'

    有人可以帮助我。

    回答

    2

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

    尝试:

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

    结果:域=%5B%22http%3A%2F%website.com%22%5D – Pixel

    +1

    在记录它看起来是这样,但如果你要打印出$ _GET [ 'domains']你将得到JSON数组作为字符串。 –

    相关问题