duankange2433 2009-07-22 06:41
浏览 8

如何在curl php中传递url值

$description = "some test data and url";
$description .="http://www.mydata.com?test=1&user=4&destination=645&source=stackoverflow";

curl_setopt($sch, CURLOPT_URL, "myserverurl");
curl_setopt($sch, CURLOPT_HEADER, 0);             
curl_setopt($sch, CURLOPT_POST, true);
curl_setopt($sch, CURLOPT_RETURNTRANSFER , 1);
curl_setopt($sch, CURLOPT_POSTFIELDS, "orgid=$orgid&description=$description&external=1");
curl_setopt ($sch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($sch, CURLOPT_SSL_VERIFYPEER, 0); 

when i check on the server (myserverurl).

I can see the description field like

"some test data and url http://www.mydata.com?test=1".

i lost the description after '&'

yes , we can encode the url before sending with curl, but i do not have access to decode the url again on that third party api server

  • 写回答

4条回答 默认 最新

  • dppfxf909679 2009-07-22 06:47
    关注

    What if you urlencode the value of each parameter you are sending ?

    You don't have to worry about decoding on the other side : it is standard way of sending data through GET / POST

    Something like :

    curl_setopt($sch, CURLOPT_POSTFIELDS, 
        "orgid=" . urlencode($orgid) 
        . "&description=" . urlencode($description) 
        . "&external=1"
    );
    

    And if this doesn't work, try with rawurlencode ? (there is a difference for spaces, if I remember correctly)

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)