php - 如何在 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);
解决方案
推荐阅读
- javascript - 如何更改 p-menu 组件的宽度/填充?
- android - 如果我将 countDownTime 作为参数传递,我的 android 倒计时计时器只会触发 onFinish()。
- javascript - d3.nest() 不是函数
- python - 如何使用 zipfile 在绝对路径上创建 zip 文件
- linux - 安装 dotnet 时出错“需要 openssl-libs”
- c++ - 如何使用textureLod在glsl中对mip级别进行采样?
- flutter - 原材料按钮不响应点击颤动
- video - ffmpeg 不正确地组合 mp4 视频
- asp.net-core - 从 asp.net 核心 Web 应用程序启动服务
- java - Android Studio 异步方法错误