我试图通过PHP中的Curl点击Census Geocoding 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);
这会导致从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 addressFile=@"C:\TestData.csv" --form benchmark=PUBLIC_AR_CENSUS2010 http://geocoding.geo.census.gov/geocoder/locations/addressbatch
知道这里出了什么问题吗?
答案 0 :(得分:1)
您可能使用的是PHP 5.6版,在这种情况下,@
功能已被弃用,默认情况下处于关闭状态。它仍然可以通过明确的curl_setopt
设置启用:
curl_setopt($curl_handle, CURLOPT_SAFE_UPLOAD, false);