【问题标题】:How to do a PHP curl post with -d option如何使用 -d 选项进行 PHP curl post
【发布时间】:2016-12-30 10:51:57
【问题描述】:

我需要发布到应用程序,其中一个数据是xml 字符串。要通过&special characters,应用程序建议curl post-d option

如何通过-d optionPHP curl

【问题讨论】:

标签: php curl post


【解决方案1】:

-d 标志是 POST 数据标志。

要通过 PHP 使用 curl 发送 POST 字段,请执行以下操作:

$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);

您将在另一端的“xmlRequest”中获取您的 XML。

【讨论】:

  • 我正在使用 CURLOPT_POSTFIELDS 来传递 xml 数据。如果数据中包含 & 符号,则请求失败。
  • urlencoding 有效,但数据以编码形式存储在应用程序中。可能是应用问题。
  • 如果答案解决了该问题,请将答案标记为已接受。另一个问题是不同的问题(发布不同的问题)。问候。
猜你喜欢
  • 2014-09-20
  • 1970-01-01
  • 1970-01-01
  • 2017-05-25
  • 1970-01-01
  • 2016-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多