dqmfo84644 2016-12-30 10:51
浏览 378

如何使用-d选项执行PHP curl post

I need to post to an application with one of the data is xml string. To pass the & and special characters, the application suggests to curl post with -d option.

How do pass -d option with PHP curl?

  • 写回答

1条回答

  • dqwh0109 2016-12-30 11:05
    关注

    The -d flag is the POST Data flag.

    To send POST fields using curl via PHP do the following:

    $ch = curl_init( $url );
    # Setup request to send xml via POST.
    $payload =  "xmlRequest=" . urlencode($input_xml);
    curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
    # Return response instead of printing.
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    # Send request.
    $result = curl_exec($ch);
    curl_close($ch);
    

    You'll get your XML in the "xmlRequest" on the other side.

    评论

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退