donglian4464 2019-04-22 10:16
浏览 62

参数不使用Php传递卷曲

I am trying to fetch data from webservice(nodejs) using curl in php but i am getting result "lang is required" i tried with following code but not working for me where i am wrong ? Here is my code

$post = ['lang'=> "593f973dea53161779dd5660",'password'=> "amit123d"];
  $ch = curl_init();
  $url="http://xxxxxx:8000/api/employer/login";
  curl_setopt($ch, CURLOPT_URL,$url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  $response = curl_exec($ch);
  $result = json_decode($response);
  echo "<pre>";print_R($result);
  • 写回答

2条回答

  • doushichun9409 2019-04-22 10:28
    关注

    Usually to send post variables i use : the http_build_query function.

    $url = "http://xxxxxx:8000/api/employer/login";
    $post = ['lang'=> "593f973dea53161779dd5660",'password'=> "amit123d"];
    
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_HEADER, false); 
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
    
    $response = curl_exec($ch);
    $result = json_decode($response);
    echo "<pre>";print_R($result);
    

    It works better.

    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)