duancan1900 2010-11-21 12:02
浏览 184
已采纳

卷曲:同时GET和POST

I want to use curl to make a request which has both GET and POST variables? How do I do it.

My priliminary understanding tells me that the only way to send POST variables is if I make the CURL request type as POST using CURLOPT_POST. However, using this, any GET variables in the url I set for CURLOPT_URL are also converted to POST - is that correct?

How to do this correctly?

regards,

JP

  • 写回答

1条回答 默认 最新

  • duanchun1909 2010-11-21 12:12
    关注

    any GET variables in the url I set for CURLOPT_URL are also converted to POST - is that correct?

    No, I don't believe it is. The following code gives both GET and POST values:

    <?php
    
    $ch = curl_init();
    curl_setopt_array($ch, array(
     CURLOPT_POST => true,
     CURLOPT_URL => 'http://localhost/test.php?getfield=text',
     CURLOPT_POSTFIELDS => array('postfield' => 'text2'),
     CURLOPT_RETURNTRANSFER => true
    ));
    
    echo curl_exec($ch);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?