search
HomeBackend DevelopmentPHP ProblemHow to handle php curl 301 jump

How to handle php curl 301 jump

Feb 03, 2023 am 11:07 AM
phpcurl

php curl 301 jump processing method: 1. Open the corresponding php file; 2. Process the 301 jump by adding the code "curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);".

How to handle php curl 301 jump

The operating environment of this tutorial: Windows 10 system, PHP version 8.1, DELL G3 computer

How to deal with php curl 301 jump ?

curl 301 processing

When I was processing an interface call, I found that postman could respond to data normally, but the normal data response could not be obtained when the program was running.

Check the log and find that curl in the code will return 301, which will cause the interface to fail to obtain the response data correctly.

curl -i http://www.example.com/fetchAvailability\?startDate\=2021-02-08\&endDate\=2021-02-08\&startTime\=00%3A00%3A00\&endTime\=23%3A59%3A59
HTTP/1.1 301 Moved Permanently
Date: Tue, 09 Feb 2021 00:39:19 GMT
OT-RequestId: 74eadfc7-50a1-4610-83ab-4beab3581621
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Set-Cookie: OT-SessionId=b1db19cb-00cf-47be-95ac-33eee1172706; Path=/; Domain=example.com; Expires=Tue, 09-Feb-2021 01:09:19 GMT; Max-Age=1800; Secure; SameSite=None
Set-Cookie: OT-Session-Update-Date=1612831159; Path=/; Domain=example.com; Expires=Tue, 09-Feb-2021 01:09:19 GMT; Max-Age=1800; Secure; SameSite=None
Location: https://www.example.com/FetchAvailability?startDate=2021-02-08&endDate=2021-02-08&startTime=00%3A00%3A00&endTime=23%3A59%3A59
Content-Length: 0

postman handles the 301 jump.

If you want to handle it in curl For 301 jump issues, you need to add the following line of code:

curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to handle php curl 301 jump. For more information, please follow other related articles on the PHP Chinese website!

Statement
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

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.