您只是错误地创建了数组。您可以使用http_build_query:
$fields = array( 'username' => "annonymous", 'api_key' => urlenpre("1234"), 'images' => array( urlenpre(base64_enpre('image1')), urlenpre(base64_enpre('image2')) ) );$fields_string = http_build_query($fields);
因此,您可以使用的整个代码为:
<?php//extract data from the postextract($_POST);//set POST variables$url = 'http://api.example.com/api';$fields = array( 'username' => "annonymous", 'api_key' => urlenpre("1234"), 'images' => array( urlenpre(base64_enpre('image1')), urlenpre(base64_enpre('image2')) ) );//url-ify the data for the POST$fields_string = http_build_query($fields);//open connection$ch = curl_init();//set the url, number of POST vars, POST datacurl_setopt($ch,CURLOPT_URL, $url);curl_setopt($ch,CURLOPT_POST, 1);curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);//execute post$result = curl_exec($ch);echo $result;//close connectioncurl_close($ch);?>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)