首页 > 解决方案 > 如何在 php 中的查询参数中传递 json Dtat 以进行拉取服务

问题描述

我正在尝试从 PHP 中的 pull 服务获取数据,而我正在调用邮递员中的端点我正在获取输出 在此处输入图像描述 ,但是当我尝试使用 PHP 调用时,我得到了 500,我已经附加了 PHP代码请指导我哪里做错了

//API Url
$url = 'https://abc.xyz/vlet?Info=';
 

//The JSON data.
$jsonData = 
    array(
    'NAME' => 'anish',
    'Key' => 'vQOgCmDgxxdw',
    'authToken' => 'xswSgsG8Dtz05Rfhfzr83t25',
    'work_date' => '2020-07-07'
    
);



//print_r( $jsonData);  exit;
//Encode the array into JSON.
$jsonDataEncoded = json_encode($jsonData);
 
$full_url = $url.$jsonDataEncoded ; 
 //echo $full_url ; 
 $result1 = file_get_contents($full_url);
  print_r( $result1); 
 //Initiate cURL.
 $curl = curl_init();
 $ch = curl_setopt($curl, CURLOPT_URL, $full_url);
//$ch = curl_init($url);

//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);
 
//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
 
//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 
 
//Execute the request
$result = curl_exec($ch);

print_r($result);

标签: phprestpull-requestphpwebsocket

解决方案


推荐阅读