`
海浪儿
  • 浏览: 272209 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Php发送请求参数丢失问题以及中文乱码问题

阅读更多

     最近由于开放平台项目的需要,在写php版的sdk,过程中碰到一些问题,做个记号,以免后面忘记

 

    Php发送请求参数丢失:

  curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString, 0, -1));

  $reponse = curl_exec($ch);

  发现请求到达服务端后,postBodyString的内容并没有出现在请求里,参数丢失

 

   解决方法:

   使用Header进行以下设置:

   $headers = array('content-type: application/x-www-form-urlencoded;charset=UTF-8'); 

   curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

 

   另外,返回结果里如果有中文,出现乱码,则也可以采用上面的方法解决。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics