Я пытаюсь попасть в API геокодирования переписи через Curl в PHP. Вот (а урезана версия) мой код:CURL Errors POSTing File
$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);
Это приводит к получаю сообщение об ошибке назад от 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."
Однако, если я призываю Curl сформировать командную строку, он отлично работает ...
curl --form [email protected]"C:\TestData.csv" --form benchmark=PUBLIC_AR_CENSUS2010 http://geocoding.geo.census.gov/geocoder/locations/addressbatch
Любая идея, что здесь не так?
Если кто-то работает, а другой делает, сравните отправленные заголовки, чтобы определить, чего не хватает. Вы можете добавить '-v' в командной строке и [прочитать самый высокий голосовой ответ] (http://stackoverflow.com/questions/3164405/show-curl-post-request-headers-is-there-a-way- to-do-this) для PHP. –