dotdx80642 2015-11-21 20:11
浏览 223
已采纳

php curl post缺少参数

I have a curl request to get some information about database and stuff, but since some user need to query many bases and most of them are not familiar with any kind of shell, we are trying to build a small page to e"xecute the query and be more user friendly

we got pretty much everything working (form and stuff) but we got really figure how to build the uery in php

here is the original working curl request we made:

curl -s - X POST -H 'Content-type:application/json' -H 'Accept:application/json' -d '{"param1":"value1","param2":"value2"} -k https:myurl -u user:password

and here is the code with the request we are trying to build:

<?php
$data = array('param1' => 'value1',
              'param2' => 'value2'
             );
$ch = curl_init();
$url = "https://myurl";
curl_setopt($ch, curlopt_url, $url);
curl_setopt($ch,curlopt_userpwd, "user:password" );
curl_setopt($ch,curlopt_post, 1);
curl_setopt($ch,curlopt_postfuelds, $data);
curl_setopt($ch,curlopt_returntransfer, true);
curl_setopt($ch,curlopt_ssl_verifypeer, false);
curl_setopt($ch,curlopt_httpheader,
    array ("Content-type:application/json"));
$output = curl_exec($ch);

curl_close($ch); 

I cannot really figure whats wrong? can you help me? I rather not use shell_exec with the curl inside because the server hosting is on windows, and we don't have curl.exe available

thanks

  • 写回答

1条回答 默认 最新

  • duanchun1852 2015-11-21 22:07
    关注

    You have a typo: curlopt_postfuelds should be curlopt_postfields

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?