对ups.com的GET请求仅返回403个一台特定主机

时间:2018-12-10 15:00:02

标签: php curl

UPS最近raised their security standards。结果,特别是在一台主机上,尝试对它们的费率API进行GET操作时得到403:

http://www.ups.com/using/services/rave/qcostcgi.cgi?accept_UPS_license_agreement=yes&10_action=4&13_product=GNDRES&14_origCountry=US&15_origPostal=98584&19_destPostal=33773&22_destCountry=US&23_weight=2.375&47_rate_chart=Regular+Daily+Pickup&48_container=00&49_residential=1

(我正在使用cURL在PHP中进行GET。)我注意到该主机正在使用较旧的cURL(7.19.7)和较旧的NSS(NSS / 3.27.1),但是我还有其他主机使用GET可以使用的这些版本。

我应该怎么做才能找出问题所在?

1 个答案:

答案 0 :(得分:1)

这很好:

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => "http://www.ups.com/using/services/rave/qcostcgi.cgi?accept_UPS_license_agreement=yes&10_action=4&13_product=GNDRES&14_origCountry=US&15_origPostal=98584&19_destPostal=33773&22_destCountry=US&23_weight=2.375&47_rate_chart=Regular+Daily+Pickup&48_container=00&49_residential=1",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_POSTFIELDS => "",
    CURLOPT_HTTPHEADER => array(
        "cache-control: no-cache"
    ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response;
}

响应:

UPSOnLine4%1DM%98584%US%33773%US%108%3%130.41%0.00%130.41% 8:00 A.M.%
4%1DA%98584%US%33773%US%108%3%98.23%0.00%98.23%10:30 A.M.%
4%1DP%98584%US%33773%US%138%3%89.08%0.00%89.08%End of Day%
4%2DA%98584%US%33773%US%208%3%45.79%0.00%45.79%End of Day%
4%3DS%98584%US%33773%US%308%3%36.05%0.00%36.05%End of Day%
4%GND%98584%US%33773%US%008%3%16.86%0.00%16.86%End of Day%