2015-01-19 3 views
1

PHP의 Curl을 통해 Census Geocoding API를 사용하려고합니다.CURL 오류 게시 파일

이이 API에서 다시 오류를 받고 결과
$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); 

: 내가 명령 줄을 형성 말림 호출 할 경우,

"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 --form [email protected]"C:\TestData.csv" --form benchmark=PUBLIC_AR_CENSUS2010 http://geocoding.geo.census.gov/geocoder/locations/addressbatch 

무엇이 잘못 되었습니까?

+0

하나가 작동하고없는 경우 전송 된 헤더를 비교하여 누락 된 항목을 확인합니다. 명령 줄에'-v'를 추가하고 [가장 높은 투표 응답을 읽습니다.] (http://stackoverflow.com/questions/3164405/show-curl-post-request-headers-is-there-a-way- to-do-this)를 PHP 용으로 사용할 수 있습니다. –

답변

1

PHP 버전 5.6 일 수 있습니다.이 경우 @ 기능은 더 이상 사용되지 않으며 기본적으로 해제되어 있습니다. 명시 적 curl_setopt 설정을 사용하여 계속 활성화 할 수 있습니다.

curl_setopt($curl_handle, CURLOPT_SAFE_UPLOAD, false); 
+1

와우, 고마워. 이미'curl_file_create'를 사용하여 전환했는데, 이제는 PHP 5.6에서 승인 한 방식대로 작동합니다 ... 그러나 이것이 왜 필요한지를 설명합니다! –

+0

더 나은 :-) –