当前位置:网站首页>Curl returns blank or null without output. Solve the problem
Curl returns blank or null without output. Solve the problem
2022-07-28 16:27:00 【Sun Fendou】
curl No output returns blank or null Problem solving
If you find a problem similar to the title , It's probably because of ssl Certificate problems cause that you only need to curl Method by adding the following code :
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// prohibit cURL Verify peer certificate
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);// Check whether the domain name of the server is consistent with that on the certificate
- Give a complete gift curl Code
/** * CURL Request function : Support POST And basic header Header definition * @param [api_url: The goal is url | post_data:post Parameters | header: Header information array | referer_url: source url] * @return [code: Status code (200 Successful implementation 、400 Perform abnormal ) | data: data ] */
function curl_request($api_url, $post_data = [], $header = [], $referer_url = ''){
$ch = curl_init();// initialization CURL Handle
curl_setopt( $ch, CURLOPT_URL, $api_url);
/** Configuration return information **/
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);// The information is returned as a file stream , No direct output
curl_setopt( $ch, CURLOPT_HEADER, 0);// No return header part
/** Configuration timeout **/
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 10);// Wait time before connecting ,0 Don't wait for
curl_setopt( $ch, CURLOPT_TIMEOUT, 5);// Wait time after connection ,0 Don't wait for . Such as download mp3
/** Configure page redirection **/
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);// Track crawl redirect page
curl_setopt( $ch, CURLOPT_MAXREDIRS, 10);// Specify the most HTTP Number of redirections
curl_setopt( $ch, CURLOPT_AUTOREFERER, 1); // Automatic setting Referer
/** To configure Header、 Request header 、 Agreement information **/
curl_setopt( $ch, CURLOPT_HTTPHEADER, $header);
curl_setopt( $ch, CURLOPT_ENCODING, "");//Accept-Encoding code , Support "identity"/"deflate"/"gzip", Null supports all codes
curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)" );// Simulate browser header information
$referer_url && curl_setopt( $ch, CURLOPT_REFERER, $referer_url);// Forge the source address
//curl_setopt( $ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 ); // Set up curl The use of HTTP agreement
/** To configure POST request **/
if($post_data && is_array($post_data)){
curl_setopt( $ch, CURLOPT_POST, 1 );// Support post Submit data
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query($post_data));//
}
/** Prohibit certificate validation to prevent curl Output blank **/
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// prohibit cURL Verify peer certificate
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);// Check whether the domain name of the server is consistent with that on the certificate
$code = 200; // Successful implementation
$data = curl_exec( $ch );
// Abnormal capture
if (curl_errno($ch)) {
$code = 400; // Perform abnormal
$data = curl_error($ch);
}
curl_close( $ch );
return ['code' => $code, 'data' => $data];
}
边栏推荐
- Ask if you don't understand, and quickly become an advanced player of container service!
- Voltage to current / current to voltage module
- The video Number finds the golden key, and Tiktok imitates the latecomers
- Automatically pack compressed backup download and delete bat script commands
- Writing of factorial
- HyperMesh自动保存(增强版)插件使用说明
- 2021 Kent interview question 2
- Roson的Qt之旅#102 ListModel
- Advantages of optical rain gauge over tipping bucket rain gauge
- 魏建军骑宝马也追不上李书福
猜你喜欢

About standard IO buffers

Why do most people who learn programming go to Shenzhen and Beijing?

使用js直传oss阿里云存储文件,解决大文件上传服务器限制

Application of optical rain gauge to rainfall detection

2021 Kent interview question 3

关于标准IO缓冲区的问题

Installation points and precautions of split angle probe

Two of C language programming!! Role of

Detectron2 installation and testing

关于web对接针式打印机问题,Lodop使用
随机推荐
Remote serial port server (adapter) UART to 1-wire application
LwIP development | realize TCP server through socket
Use py to automatically generate weekly reports based on log records
2021-04-02
500million users, four years earlier than wechat... This app, which has been in operation for 15 years, will be permanently discontinued
五舅的思考
百度编辑器ueditor,编辑内容过多时,工具栏不可见,不方便编辑或上传问题
2021-10-21 notes
疫情红利消失,「居家健身」泡沫消散
R language uses file of FS package_ Delete function deletes the specified file under the specified folder, draw inferences from one instance, dir_ Delete function, link_ The delete function can be use
Stm32cube infrared remote control: input capture
R language uses ggpairs function of ggally package to visualize pairwise relationship graph of grouping multivariable, set alpha parameter to change image transparency, diagonal continuous variable de
JS array (summary)
不懂就问,快速成为容器服务进阶玩家!
Reentrant and non reentrant
mysql查询 limit 1000,10 和limit 10 速度一样快吗?如果我要分页,我该怎么办?
Why do most people who learn programming go to Shenzhen and Beijing?
Advantages of optical rain gauge over tipping bucket rain gauge
软考 系统架构设计师 简明教程 | 软件调试
Redis系列4:高可用之Sentinel(哨兵模式)