PHP를 사용하여이 API의 출력을 얻으려고합니다. 호주 우체국 운임 계산기입니다. 나는 그것이 무엇이 잘못되었는지 확신하지 못한다. 정말 도움이 될 것입니다.PHP에서 API 출력을 얻으려고 시도합니다.
// Set your API key: remember to change this to your live API key in production
$apiKey = API_KEY;
// Set the URL for the Domestic Parcel Size service
$urlPrefix = URL_PREFIX;
$parcelTypesURL = 'https://' . $urlPrefix . '/postage/parcel/domestic/size.json';
// Lookup domestic parcel types (different kinds of standard boxes etc)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $parcelTypesURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('AUTH-KEY: ' . $apiKey));
$rawBody = curl_exec($ch);
// Check the response: if the body is empty then an error occurred
if(!$rawBody){
die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
}
// All good, lets parse the response into a JSON object
$parcelTypesJSON = json_decode($rawBody);
API 키인 경우이를 숨겨야합니다. 이 코드가 오류를 발생시키는 것입니까? – Luke
그 코드가 작동합니다. 'print_r ($ ParcelTypesJSON)'은 예상했던 데이터를 보여줍니다. 오류가 있으면 해당 코드 외부에 있습니다. – Luke
경고 번호 9의 보안상의 이유로 curl_init()가 비활성화되었습니다. 이것은 경고 중 하나이며이 키는 숨기지 않은 테스트 용입니다 – ovic