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.

    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记