Home > php教程 > php手册 > body text

PHP函数之CURL: 常见问题总结

WBOY
Release: 2016-06-06 19:44:52
Original
1187 people have browsed it

一. 请求返回400 bad request错误, 可能原因: 1. url地址有误. 手动在地址栏里输入url看看请求是否正常. 注意: 如果url地址里面包含换行符也有可能返回400. 2. https请求需要设置对应参数 ## Below two option will enable the HTTPS option. curl_setopt($c

一. 请求返回"400 bad request"错误, 可能原因:

1. url地址有误.

  手动在地址栏里输入url看看请求是否正常.

  注意: 如果url地址里面包含换行符也有可能返回400.

2. https请求需要设置对应参数

  ## Below two option will enable the HTTPS option.
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  FALSE);

3. url中传递的字符串需要url_encode转码

 

二. 允许url重定向的设置:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects

 

三. POST提交数据

  curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
  curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包
  curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!