1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > api.cls.php文件 php数据POST提交到API接口

api.cls.php文件 php数据POST提交到API接口

时间:2020-07-18 17:35:23

相关推荐

api.cls.php文件 php数据POST提交到API接口

/**

* php数据POST提交到API接口

*/

static public function post_to_heinz($url_head,$url_param)

{

$remote_url_address = ‘http://xxxxxx:8000/’.$url_head;

ClsTools::logRec(‘$remote_url_address:’);

ClsTools::logRec($remote_url_address);

ClsTools::logRec(‘$url_param:’);

ClsTools::logRec($url_param);

$url_param = http_build_query($url_param);

ClsTools::logRec($url_param);

//die();

$result = array();

try {

$context = array(

‘http’ => array(

‘method’ => ‘POST’,

‘header’ => ‘Content-type: application/x-www-form-urlencoded;charset=UTF-8’,

‘content’ => $url_param)

);

$stream_context = stream_context_create($context);

$result[‘data’] = file_get_contents($remote_url_address, false, $stream_context);

if(empty($result[‘data’])) {

$result[‘error’] = ‘连接接口失败’;

}

} catch(Exception $e) {

$result[‘error’] = ‘file_get_contents exception:’.$e->getMessage();

}

ClsTools::logRec(‘post_result:’);

ClsTools::logRec($result);

return $result;

}

小杰博客 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权

转载请注明原文链接:php数据POST提交到API接口

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。