Reputation: 3973
I'm trying to hit the Census Geocoding API via Curl in PHP. Here's (a trimmed down version of) my code:
$post = array('benchmark' => 'Public_AR_CENSUS2010', 'addressFile'=>'@C:\TestData.csv');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://geocoding.geo.census.gov/geocoder/locations/addressbatch/');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
echo($result);
curl_close ($ch);
This results in getting an error back from the API:
"From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1: 10.4.1 400 Bad Request. The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications."
However, if I invoke Curl form the command line, it works fine...
curl --form addressFile=@"C:\TestData.csv" --form benchmark=PUBLIC_AR_CENSUS2010 http://geocoding.geo.census.gov/geocoder/locations/addressbatch
Any idea what's going wrong here?
Upvotes: 1
Views: 470
Reputation: 53958
You may be on PHP version 5.6, in which case the @
feature is deprecated and turned off by default. It can still be enabled by explicit curl_setopt
setting:
curl_setopt($curl_handle, CURLOPT_SAFE_UPLOAD, false);
Upvotes: 1