php 发送http请求
生活随笔
收集整理的這篇文章主要介紹了
php 发送http请求
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
//發送http請求function do_post_request($url, $data, $optional_headers = null){$params = array('http' => array('method' => 'POST','content' => $data));if ($optional_headers !== null) {$params['http']['header'] = $optional_headers;}$ctx = stream_context_create($params);$fp = @fopen($url, 'rb', false, $ctx);if (!$fp) {throw new Exception("Problem with $url, $php_errormsg");}$response = @stream_get_contents($fp);if ($response === false) {throw new Exception("Problem reading data from $url, $php_errormsg");}return $response;}public function do_post($url, $post_data = '', $timeout = 5){$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_POST, 1);if ($post_data != '') {curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);}curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);curl_setopt($ch, CURLOPT_HEADER, false);$file_contents = curl_exec($ch);curl_close($ch);return $file_contents;}轉載于:https://my.oschina.net/objectboy/blog/1559820
總結
以上是生活随笔為你收集整理的php 发送http请求的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 告警系统邮件引擎、运行告警系统
- 下一篇: 2017年软件工程第七次作业-每周例行报