【问题标题】:Can not send ampersand + curren via curl post ($currency=A&otherkey=B)无法通过 curl post ($currency=A&otherkey=B) 发送 & 符号 + curren
【发布时间】:2018-01-10 16:20:10
【问题描述】:

我在处理 curl 的 POST 字符串中遇到 ampersand + curren 问题 - 而不是 POST 值我得到了阳光字符 - ¤。

我的问题是: 如何发送

['货币' => 'somevalue', 'otherkey' => 'othervalue']

通过 curl 使用 POST

我尝试将我的 POST 设置为

$post_val = "otherVal=1&currency=USD";

$post_val = "otherVal=1&currency=USD";

$post_val = urlencode("otherVal=1&currency=USD");

然后

curl_setopt($ch, CURLOPT_POSTFIELDS, $post_val);

奇怪的是 - 当我将货币作为字符串中的第一个传递时,它会产生相同的效果 - “currency=USD&otherVal=1”。

我也试过了

$array = http_build_query(['currency' => 'somevalue', 'otherkey' => 'othervalue']);

curl_setopt($ch, CURLOPT_POSTFIELDS, $array);

也许 curl 总是使 http_build_query 也给出一些源服务器无法正确解释的附加标志?

有什么办法解决吗?

干杯

【问题讨论】:

  • ¤ 转换为货币符号 ¤。但是当&currency 甚至&currency 翻译成同一个符号时,这确实有点奇怪。您是否在服务器端的 $_POST 数组中看到此符号?
  • 你试过$post_val = array('otherVal' => 1, 'currency' => 'USD');吗?
  • 不幸的是,我对服务器端一无所知。我只是总结一下效果。发送一个帖子值 -> 正确,发送几个 -> 错误。

标签: php curl post currency ampersand


【解决方案1】:

简单的出路

$data = array('otheritem'=>'item', 'currency'=>'usd');
curl_setopt($ch, CURLOPT_POST,TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

这应该可以工作

【讨论】:

    猜你喜欢
    • 2013-04-02
    • 1970-01-01
    • 2010-09-19
    • 1970-01-01
    • 2012-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-28
    相关资源
    最近更新 更多