Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial curl请求 https结果不对

curl请求 https结果不对

Jun 20, 2016 pm 12:36 PM

环境是 windows  wamp  php5.5

------------------------------------------
程序写法:
 $ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
//$url = 'https://sp0.baidu.com/9_Q4sjW91Qh3otqbppnN2DJv/pae/channel/data/asyncqury?cb=jQuery110208172749384481603_1456294051449&appid=4001&com=shentong&nu=3304810729274&vcode=&token=&_=1456294051453';
$url = 'https://sp0.baidu.com/9_Q4sjW91Qh3otqbppnN2DJv/pae/channel/data/asyncqury?cb=jQuery110208172749384481603_1456294051449&appid=4001&com=jd&nu=12148326312&vcode=&token=&_=1456294051453';
//$url ='https://www.jb51.net';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);//这个是重点。
$data = curl_exec($curl);
curl_close($curl);
echo ($data);
---------------------------------------------------------------
直接在地址栏输入 :
https://sp0.baidu.com/9_Q4sjW91Qh3otqbppnN2DJv/pae/channel/data/asyncqury?cb=jQuery110208172749384481603_1456294051449&appid=4001&com=jd&nu=12148326312&vcode=&token=&_=1456294051453
得到结果是


两个结果不一样,查了一些信息,dll 什么的,加了也不好用。帮忙你们测一下。  解决一下,谢谢


回复讨论(解决方案)

缺少 cookie 的接收和传递



前辈我的意思是,可以直接用CURL请求  HTTPS这上地址不。  这里没有发现传递值的关系啊
就是一个请求,然后把值解析出来。 (这是个物流接口,我从网上拔下来的

或有什么更好的接口没,谢谢

1

$url = 'https://sp0.baidu.com/9_Q4sjW91Qh3otqbppnN2DJv/pae/channel/data/asyncqury?cb=jQuery110208172749384481603_1456294051449&appid=4001&com=jd&nu=12148326312&vcode=&token=&_=1456294051453';$cookie = tempnam("/tmp", "cookie");$t = parse_url($url);//先获取 cookie$curl = curl_init();curl_setopt($curl, CURLOPT_URL, "$t[scheme]://$t[host]/$t[path]");curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie);curl_exec($curl);//再获取数据$curl = curl_init();curl_setopt($curl, CURLOPT_URL, $url);curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie);$data = curl_exec($curl);curl_close($curl);//解析得到的 jsonp 数据$s = preg_replace('/^.*\((.+)\).*/', '$1', $data);print_r(json_decode($s, 1));

Copy after login

1

Array(    [msg] =>     [status] => 0    [data] => Array        (            [info] => Array                (                    [status] => 1                    [com] => jd                    [state] => 3                    [context] => Array                        (                            [0] => Array                                (                                    [time] => 1456304591                                    [desc] => 货物已完成配送,感谢您选择京东配送                                )                            [1] => Array                                (                                    [time] => 1456299587                                    [desc] => 配送员开始配送,请您准备收货,配送员,郭林伟,手机号,18511532257                                )                            [2] => Array                                (                                    [time] => 1456298302                                    [desc] => 货物已分配,等待配送                                )                            [3] => Array                                (                                    [time] => 1456298298                                    [desc] => 货物已到达【东大桥站】                                )                            [4] => Array                                (                                    [time] => 1456292041                                    [desc] => 货物已完成分拣,离开【北京小杜社分拣中心】                                )                            [5] => Array                                (                                    [time] => 1456291522                                    [desc] => 货物已到达【北京小杜社分拣中心】                                )                            [6] => Array                                (                                    [time] => 1456284653                                    [desc] => 货物已完成分拣,离开【北京土桥接货仓】                                )                            [7] => Array                                (                                    [time] => 1456284549                                    [desc] => 货物已交付京东快递                                )                            [8] => Array                                (                                    [time] => 1456284549                                    [desc] => 货物已到达【北京土桥接货仓】                                )                        )                    [_source_com] =>                 )            [com] => jd            [company] => Array                (                    [url] => http://www.kuaidi100.com/all/jd.shtml?from=openv                    [fullname] => 京东快递                    [shortname] => 京东                    [icon] => Array                        (                            [id] =>                             [smallurl] => https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=1807529516,3291075151&fm=58                            [smallpos] => 0,1504                            [middleurl] => https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=1835223070,3312272045&fm=58                            [middlepos] => 0,900                            [normal] => https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=2992147315,359626353&fm=58                        )                    [website] => Array                        (                            [title] => www.jd-ex.com                            [url] => http://www.jd-ex.com/                        )                    [tel] => 400-603-3600                    [auxiliary] => Array                        (                            [0] => Array                                (                                    [title] => 运费查询                                    [url] => http://jd-ex.com/#searchFreight                                )                            [1] => Array                                (                                    [title] => 禁运规则                                    [url] => http://jd-ex.com/forbid.html                                )                        )                )            [source] => Array                (                    [logo] => https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=1429564979,1787167512&fm=58                    [title] => 数据来自快递100                    [url] => http://www.kuaidi100.com/                    [name] => 快递100                )        ))

Copy after login

1

 

Copy after login



thanks
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

See all articles