API 在 POSTMAN 上运行良好,但在 Curl 上出错 PHP
API working well on POSTMAN but giving error in Curl PHP
我正在尝试从 api 中获取记录。它在邮递员上工作正常,但在 php.
中使用 curl 时出现错误
这是我的 PHP 代码:
function GETAPISRecord(){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => https://data.medicare.gov/resource/6jpm-sxkc.json?$where=provider_number in("017000","017037","017055","017056","017116","017319","017324"),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"cache-control: no-cache",
),
));
$response = curl_exec($curl);
if($debug){
// dd($url);
dd($response);
}
return json_decode($response, true);
}
这是我在 curl 后遇到的错误:
error after curl option
在 Postman 上,它给出了预期的完美结果:
postman result
此外 api url working perfect without any parameters on search. it is also working fine if we use the zip_code filter like this zipcode filter 唯一的问题是 $where=provider_number in("017000","017037","017055","017056 ","017116","017319","017324")
如果body知道如何以Laravel方式解决这个问题,他也可以回答这个问题。
编辑:添加邮递员中的 Curl headers
curl 7 headers
由于我提供的 url,我遇到了问题。我应该避免使用空格,并在 curl api
中将它们替换为 %20 和逗号 (") 到 %22
在 php 中,我的 curl 将是这样的:
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://data.medicare.gov/resource/6jpm-sxkc.json?$where=provider_number%20in(%22017000%22,%22017037%22,%22017055%22,%22017056%22,%22017116%22,%22017319%22,%22017324%22)",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Cookie: _frontend_session=Sld3TFdrNEFIWmpJRnV4a2JveHpDc3F3T3dHd1lpak5idzByL1VVTHNQSEpSU2hlNEZxRDlPbjd1cG1TNzVyaVRERzg4ZGNDYkZCV1h3TXBlNWE3a1JRWnU0dTN3R2dMa3JST0xObVhjM2ZoMGlJZk5MN211Qkxtb3ErSmZ6OGVPZFBwc2tJVDJwQXRwQllrVXloQUFBPT0tLThZeHZZYk9SL3IzMUU3aU16RUordXc9PQ%3D%3D--e3eb18669fa6c2e905a40ffff0c33b559e0e241b; ak_bmsc=745EECBD67F7301E4B7311809DFAE6DC68788BC621610000997F775F7DEE2B48~plyfmyJzyR+AfIF/Np8ucZmQIrMNlYOCjSqJWkFlzOJaVhe+8AtA+XDOYdtvT0/tRLH+xgXE8bRjqc+SfoLVQ+1/26CLzz6LKnTKHrki68a5GB42zBY1YR2CaW/pyJyyK/2ByXsuKfPYfRj94udk+L1LAX0ksKnKIvcYURkPjwo8gMJpTaPb7l6IbBxAQWX2S6izEKTsaKo+ZlUHLKmMG60anU3k1DvNs50YhrvgppYUc=; bm_sv=3283155D1D2681C3CB7F831A5C8E51EB~tPx4bluLNUcZLdNKSDT9178Ehspi63N1nZIElfhOt/SoHh97ihVROaVGwOseGzU3yfYzOhRmau/0Zde2PJAx5OISYkav8uPzxD1biUDX7vPYDFQXPlcbyz3Q0XoWQjfhS0FLXxnkkw5RMUQ+3ZwnxbIAyVGL/eebL6R8LE3wT/8="
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
祝你好运
我正在尝试从 api 中获取记录。它在邮递员上工作正常,但在 php.
中使用 curl 时出现错误这是我的 PHP 代码:
function GETAPISRecord(){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => https://data.medicare.gov/resource/6jpm-sxkc.json?$where=provider_number in("017000","017037","017055","017056","017116","017319","017324"),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"cache-control: no-cache",
),
));
$response = curl_exec($curl);
if($debug){
// dd($url);
dd($response);
}
return json_decode($response, true);
}
这是我在 curl 后遇到的错误: error after curl option
在 Postman 上,它给出了预期的完美结果: postman result
此外 api url working perfect without any parameters on search. it is also working fine if we use the zip_code filter like this zipcode filter 唯一的问题是 $where=provider_number in("017000","017037","017055","017056 ","017116","017319","017324")
如果body知道如何以Laravel方式解决这个问题,他也可以回答这个问题。
编辑:添加邮递员中的 Curl headers curl 7 headers
由于我提供的 url,我遇到了问题。我应该避免使用空格,并在 curl api
中将它们替换为 %20 和逗号 (") 到 %22在 php 中,我的 curl 将是这样的:
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://data.medicare.gov/resource/6jpm-sxkc.json?$where=provider_number%20in(%22017000%22,%22017037%22,%22017055%22,%22017056%22,%22017116%22,%22017319%22,%22017324%22)",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Cookie: _frontend_session=Sld3TFdrNEFIWmpJRnV4a2JveHpDc3F3T3dHd1lpak5idzByL1VVTHNQSEpSU2hlNEZxRDlPbjd1cG1TNzVyaVRERzg4ZGNDYkZCV1h3TXBlNWE3a1JRWnU0dTN3R2dMa3JST0xObVhjM2ZoMGlJZk5MN211Qkxtb3ErSmZ6OGVPZFBwc2tJVDJwQXRwQllrVXloQUFBPT0tLThZeHZZYk9SL3IzMUU3aU16RUordXc9PQ%3D%3D--e3eb18669fa6c2e905a40ffff0c33b559e0e241b; ak_bmsc=745EECBD67F7301E4B7311809DFAE6DC68788BC621610000997F775F7DEE2B48~plyfmyJzyR+AfIF/Np8ucZmQIrMNlYOCjSqJWkFlzOJaVhe+8AtA+XDOYdtvT0/tRLH+xgXE8bRjqc+SfoLVQ+1/26CLzz6LKnTKHrki68a5GB42zBY1YR2CaW/pyJyyK/2ByXsuKfPYfRj94udk+L1LAX0ksKnKIvcYURkPjwo8gMJpTaPb7l6IbBxAQWX2S6izEKTsaKo+ZlUHLKmMG60anU3k1DvNs50YhrvgppYUc=; bm_sv=3283155D1D2681C3CB7F831A5C8E51EB~tPx4bluLNUcZLdNKSDT9178Ehspi63N1nZIElfhOt/SoHh97ihVROaVGwOseGzU3yfYzOhRmau/0Zde2PJAx5OISYkav8uPzxD1biUDX7vPYDFQXPlcbyz3Q0XoWQjfhS0FLXxnkkw5RMUQ+3ZwnxbIAyVGL/eebL6R8LE3wT/8="
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
祝你好运