简体   繁体   English

使用 post 时从 Ogre 收到错误“No JSON provided”,但是当使用在线转换器时识别相同的 881569990078588

[英]Getting error "No JSON provided" from Ogre when using post, but when use online converter same JSON is recognized

I'm troubleshooting an issue trying to use Ogre to convert a GeoJSON to a Shapefile.我正在解决尝试使用 Ogre 将 GeoJSON 转换为 Shapefile 的问题。

I was trying using php curl_exec, and also with Postman, and get the same response with each:我尝试使用 php curl_exec,也尝试使用 Postman,并得到相同的响应:

{
    "error": true,
    "msg": "No json provided"
}

However, when I paste the json into their web tool here, it successfully converts: https://ogre.adc4gis.com/但是,当我将 json 粘贴到他们的 web 工具中时,它成功转换: https://ogre.adc4gis.com/

My php code looks like this:我的 php 代码如下所示:

           $posturl = "https://ogre.adc4gis.com/convertJson";
           $params = array('json'=>$geojson);
           $ch = curl_init();
           curl_setopt($ch, CURLOPT_FILE, $out);
           curl_setopt($ch, CURLOPT_URL, $posturl);
           curl_setopt($ch, CURLOPT_HEADER, false);
           curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
           curl_setopt($ch, CURLOPT_POST, 1);
           curl_setopt($ch, CURLOPT_POSTFIELDS, $params);         
           curl_setopt($ch, CURLOPT_VERBOSE, true);
           $streamVerboseHandle = fopen($CI->config->item('log_path').'curl_log.log', 'w+');
           cucurl_execrl_setopt($ch, CURLOPT_STDERR, $streamVerboseHandle);
           $output = curl_exec($ch);
           curl_close($ch);

$params looks like this: $params 看起来像这样:

(
    [json] => {"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[-73.32271671155468,44.55490573909421]},"properties":{"fldOriginalCode":"CR","fldOriginalValue":"Colchester Reef","fldDescription":"Estimated location of Colchester Reef"}}]}
)

I'm not sure why I can't get it to convert using a post request?我不确定为什么无法使用发布请求进行转换?

Thank you!谢谢!

It ended up working with this:它最终使用了这个:

curl_setopt($ch, CURLOPT_POSTFIELDS, "json=$geojson");

instead of代替

curl_setopt($ch, CURLOPT_POSTFIELDS, $params); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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