简体   繁体   中英

cURL Request: POST data is received by server, but returns invalid request

I am attempting to query the NOTAM database ( https://www.notams.faa.gov ) in order to have the server parse the NOTAMs for display on a map, code is PHP.

I'm using cURL to send the POST data, however, the server is returning an "invalid request". Here is the POST data I'm sending to the server. It is exactly what is sent during a request from the homepage (discovered using Fiddler). The NOTAMs needed are the "RKRR" ICAO (airport code for Incheon Center here in Korea).

What am I missing here?

$url = "https://www.notams.faa.gov/dinsQueryWeb/queryRetrievalMapAction.do";
$ch = curl_init($url);

$header = array('Host: www.notams.faa.gov', 'Content-Type: application/x-www-form-urlencoded',      'Connection: keep-alive', 'Cache-Control: max-age=0', 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/*;q=0.8', 'User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36', 'Referer: https://www.notams.faa.gov/dinsQueryWeb/', 'Accept-Encoding: gzip,deflate', 'Accept-Language: en-US,en;q=0.8', 'Origin: https://www.notams.faa.gov');

$data = 'retrieveLocId=rkrr&reportType=Raw&submit=View+NOTAMSs&actionType=notamRetriealByICAOs';
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);


$response = curl_exec($ch);

echo $response;
curl_close($ch);

Thanks for the help!

Seems you have a typo in variable $data value

$data = 'retrieveLocId=rkrr&reportType=Raw&submit=View+NOTAMSs&actionType=notamRetriealByICAOs';

Its actually

$data = 'retrieveLocId=rkrr&reportType=Raw&actionType=notamRetrievalByICAOs&submit=View+NOTAMSs';

Its not notamRetriealByICAOs

its notamRetrievalByICAOs

Give a try

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM