Làm cách nào để đọc tải trọng yêu cầu trong php?

Bạn có thể tùy chỉnh các yêu cầu do khách hàng tạo và chuyển bằng các tùy chọn yêu cầu. Tùy chọn yêu cầu kiểm soát các khía cạnh khác nhau của yêu cầu bao gồm, tiêu đề, tham số chuỗi truy vấn, cài đặt thời gian chờ, phần thân của yêu cầu, v.v.

Tất cả các ví dụ sau đều sử dụng ứng dụng khách sau

$client = new GuzzleHttp\Client[['base_uri' => '//httpbin.org']];

allow_redirects¶

Tóm lược

Mô tả hành vi chuyển hướng của một yêu cầu

các loại
  • bool
  • mảng
Mặc định

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]

Hằng số

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
2

Đặt thành

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
3 để tắt chuyển hướng

$res = $client->request['GET', '/redirect/3', ['allow_redirects' => false]];
echo $res->getStatusCode[];
// 302

Đặt thành

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
4 [cài đặt mặc định] để bật chuyển hướng bình thường với số lần chuyển hướng tối đa là 5

$res = $client->request['GET', '/redirect/3'];
echo $res->getStatusCode[];
// 200

Bạn cũng có thể chuyển một mảng kết hợp chứa các cặp giá trị khóa sau

  • tối đa. [int, default=5] số lần chuyển hướng tối đa được phép

  • nghiêm khắc. [bool, default=false] Đặt thành true để sử dụng chuyển hướng nghiêm ngặt. Chuyển hướng tuân thủ RFC nghiêm ngặt có nghĩa là yêu cầu chuyển hướng POST được gửi dưới dạng yêu cầu POST so với. làm những gì mà hầu hết các trình duyệt làm đó là chuyển hướng các yêu cầu POST bằng các yêu cầu GET

  • người giới thiệu. [bool, default=false] Đặt thành true để cho phép thêm tiêu đề Người giới thiệu khi chuyển hướng

  • giao thức. [mảng, mặc định=['http', 'https']] Đã chỉ định giao thức nào được phép cho các yêu cầu chuyển hướng

  • on_redirect. [có thể gọi] PHP có thể gọi được gọi khi gặp chuyển hướng. Có thể gọi được gọi với yêu cầu ban đầu và phản hồi chuyển hướng đã nhận được. Mọi giá trị trả về từ hàm on_redirect đều bị bỏ qua

  • track_redirects. [bool] Khi được đặt thành

    use Psr\Http\Message\RequestInterface;
    use Psr\Http\Message\ResponseInterface;
    use Psr\Http\Message\UriInterface;
    
    $onRedirect = function[
        RequestInterface $request,
        ResponseInterface $response,
        UriInterface $uri
    ] {
        echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
    };
    
    $res = $client->request['GET', '/redirect/3', [
        'allow_redirects' => [
            'max'             => 10,        // allow at most 10 redirects.
            'strict'          => true,      // use "strict" RFC compliant redirects.
            'referer'         => true,      // add a Referer header
            'protocols'       => ['https'], // only allow https URLs
            'on_redirect'     => $onRedirect,
            'track_redirects' => true
        ]
    ]];
    
    echo $res->getStatusCode[];
    // 200
    
    echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
    // //first-redirect, //second-redirect, etc...
    
    echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
    // 301, 302, etc...
    
    4, mỗi URI được chuyển hướng và mã trạng thái gặp phải sẽ được theo dõi trong tiêu đề
    use Psr\Http\Message\RequestInterface;
    use Psr\Http\Message\ResponseInterface;
    use Psr\Http\Message\UriInterface;
    
    $onRedirect = function[
        RequestInterface $request,
        ResponseInterface $response,
        UriInterface $uri
    ] {
        echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
    };
    
    $res = $client->request['GET', '/redirect/3', [
        'allow_redirects' => [
            'max'             => 10,        // allow at most 10 redirects.
            'strict'          => true,      // use "strict" RFC compliant redirects.
            'referer'         => true,      // add a Referer header
            'protocols'       => ['https'], // only allow https URLs
            'on_redirect'     => $onRedirect,
            'track_redirects' => true
        ]
    ]];
    
    echo $res->getStatusCode[];
    // 200
    
    echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
    // //first-redirect, //second-redirect, etc...
    
    echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
    // 301, 302, etc...
    
    6 và
    use Psr\Http\Message\RequestInterface;
    use Psr\Http\Message\ResponseInterface;
    use Psr\Http\Message\UriInterface;
    
    $onRedirect = function[
        RequestInterface $request,
        ResponseInterface $response,
        UriInterface $uri
    ] {
        echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
    };
    
    $res = $client->request['GET', '/redirect/3', [
        'allow_redirects' => [
            'max'             => 10,        // allow at most 10 redirects.
            'strict'          => true,      // use "strict" RFC compliant redirects.
            'referer'         => true,      // add a Referer header
            'protocols'       => ['https'], // only allow https URLs
            'on_redirect'     => $onRedirect,
            'track_redirects' => true
        ]
    ]];
    
    echo $res->getStatusCode[];
    // 200
    
    echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
    // //first-redirect, //second-redirect, etc...
    
    echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
    // 301, 302, etc...
    
    7 tương ứng. Tất cả các URI và mã trạng thái sẽ được lưu trữ theo thứ tự chuyển hướng gặp phải

    Ghi chú. Khi theo dõi chuyển hướng, tiêu đề

    use Psr\Http\Message\RequestInterface;
    use Psr\Http\Message\ResponseInterface;
    use Psr\Http\Message\UriInterface;
    
    $onRedirect = function[
        RequestInterface $request,
        ResponseInterface $response,
        UriInterface $uri
    ] {
        echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
    };
    
    $res = $client->request['GET', '/redirect/3', [
        'allow_redirects' => [
            'max'             => 10,        // allow at most 10 redirects.
            'strict'          => true,      // use "strict" RFC compliant redirects.
            'referer'         => true,      // add a Referer header
            'protocols'       => ['https'], // only allow https URLs
            'on_redirect'     => $onRedirect,
            'track_redirects' => true
        ]
    ]];
    
    echo $res->getStatusCode[];
    // 200
    
    echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
    // //first-redirect, //second-redirect, etc...
    
    echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
    // 301, 302, etc...
    
    6 sẽ loại trừ URI của yêu cầu ban đầu và tiêu đề
    use Psr\Http\Message\RequestInterface;
    use Psr\Http\Message\ResponseInterface;
    use Psr\Http\Message\UriInterface;
    
    $onRedirect = function[
        RequestInterface $request,
        ResponseInterface $response,
        UriInterface $uri
    ] {
        echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
    };
    
    $res = $client->request['GET', '/redirect/3', [
        'allow_redirects' => [
            'max'             => 10,        // allow at most 10 redirects.
            'strict'          => true,      // use "strict" RFC compliant redirects.
            'referer'         => true,      // add a Referer header
            'protocols'       => ['https'], // only allow https URLs
            'on_redirect'     => $onRedirect,
            'track_redirects' => true
        ]
    ]];
    
    echo $res->getStatusCode[];
    // 200
    
    echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
    // //first-redirect, //second-redirect, etc...
    
    echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
    // 301, 302, etc...
    
    7 sẽ loại trừ mã trạng thái cuối cùng

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...

Cảnh báo

Tùy chọn này chỉ có tác dụng nếu trình xử lý của bạn có phần mềm trung gian

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
30. Phần mềm trung gian này được thêm theo mặc định khi ứng dụng khách được tạo không có trình xử lý và được thêm theo mặc định khi tạo trình xử lý với
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
31

Ghi chú

Tùy chọn này không có hiệu lực khi thực hiện yêu cầu bằng cách sử dụng

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
32. Để luôn tuân thủ PSR-18, mọi phản hồi chuyển hướng đều được trả về như hiện tại

xác thực¶

Tóm lược

Truyền một mảng tham số xác thực HTTP để sử dụng với yêu cầu. Mảng phải chứa tên người dùng trong chỉ mục [0], mật khẩu trong chỉ mục [1] và bạn có thể tùy chọn cung cấp loại xác thực tích hợp trong chỉ mục [2]. Vượt qua

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
33 để tắt xác thực cho yêu cầu

các loại
  • mảng
  • chuỗi
  • vô giá trị
Mặc định

Không có

Hằng số

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
34

Các loại xác thực tích hợp như sau

basicSử dụng xác thực HTTP cơ bản trong tiêu đề
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
35 [cài đặt mặc định được sử dụng nếu không được chỉ định]

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
3

digestSử dụng xác thực thông báo [phải được trình xử lý HTTP hỗ trợ]

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
0

Ghi chú

Điều này hiện chỉ được hỗ trợ khi sử dụng trình xử lý cURL, nhưng việc tạo một thay thế có thể được sử dụng với bất kỳ trình xử lý HTTP nào đã được lên kế hoạch

ntlmSử dụng xác thực NTLM của Microsoft [phải được trình xử lý HTTP hỗ trợ]

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
1

Ghi chú

Điều này hiện chỉ được hỗ trợ khi sử dụng trình xử lý cURL

thân thể¶

Tóm lược

Tùy chọn

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
36 được sử dụng để kiểm soát phần thân của thực thể kèm theo yêu cầu [e. g. , PUT, POST, VÁ]

các loại
  • chuỗi
  • tài nguyên
    [
        'max'             => 5,
        'strict'          => false,
        'referer'         => false,
        'protocols'       => ['http', 'https'],
        'track_redirects' => false
    ]
    
    37
  • [
        'max'             => 5,
        'strict'          => false,
        'referer'         => false,
        'protocols'       => ['http', 'https'],
        'track_redirects' => false
    ]
    
    38
Mặc định

Không có

Hằng số

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
39

Cài đặt này có thể được đặt thành bất kỳ loại nào sau đây

  • chuỗi

    use Psr\Http\Message\RequestInterface;
    use Psr\Http\Message\ResponseInterface;
    use Psr\Http\Message\UriInterface;
    
    $onRedirect = function[
        RequestInterface $request,
        ResponseInterface $response,
        UriInterface $uri
    ] {
        echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
    };
    
    $res = $client->request['GET', '/redirect/3', [
        'allow_redirects' => [
            'max'             => 10,        // allow at most 10 redirects.
            'strict'          => true,      // use "strict" RFC compliant redirects.
            'referer'         => true,      // add a Referer header
            'protocols'       => ['https'], // only allow https URLs
            'on_redirect'     => $onRedirect,
            'track_redirects' => true
        ]
    ]];
    
    echo $res->getStatusCode[];
    // 200
    
    echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
    // //first-redirect, //second-redirect, etc...
    
    echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
    // 301, 302, etc...
    
    6

  • tài nguyên được trả về từ

    [
        'max'             => 5,
        'strict'          => false,
        'referer'         => false,
        'protocols'       => ['http', 'https'],
        'track_redirects' => false
    ]
    
    37

    use Psr\Http\Message\RequestInterface;
    use Psr\Http\Message\ResponseInterface;
    use Psr\Http\Message\UriInterface;
    
    $onRedirect = function[
        RequestInterface $request,
        ResponseInterface $response,
        UriInterface $uri
    ] {
        echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
    };
    
    $res = $client->request['GET', '/redirect/3', [
        'allow_redirects' => [
            'max'             => 10,        // allow at most 10 redirects.
            'strict'          => true,      // use "strict" RFC compliant redirects.
            'referer'         => true,      // add a Referer header
            'protocols'       => ['https'], // only allow https URLs
            'on_redirect'     => $onRedirect,
            'track_redirects' => true
        ]
    ]];
    
    echo $res->getStatusCode[];
    // 200
    
    echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
    // //first-redirect, //second-redirect, etc...
    
    echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
    // 301, 302, etc...
    
    8

  • [
        'max'             => 5,
        'strict'          => false,
        'referer'         => false,
        'protocols'       => ['http', 'https'],
        'track_redirects' => false
    ]
    
    38

    [
        'max'             => 5,
        'strict'          => false,
        'referer'         => false,
        'protocols'       => ['http', 'https'],
        'track_redirects' => false
    ]
    
    0

Ghi chú

Không thể sử dụng tùy chọn này với

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
02,
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
03 hoặc
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
04

chứng chỉ¶

Tóm lược

Đặt thành một chuỗi để chỉ định đường dẫn đến tệp chứa chứng chỉ phía máy khách được định dạng PEM. Nếu mật khẩu được yêu cầu, thì hãy đặt thành một mảng chứa đường dẫn đến tệp PEM trong phần tử mảng đầu tiên, theo sau là mật khẩu cần thiết cho chứng chỉ trong phần tử mảng thứ hai

các loại
  • chuỗi
  • mảng
Mặc định

Không có

Hằng số

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
05

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
1

bánh quy¶

Tóm tắtChỉ định có sử dụng cookie trong một yêu cầu hay không hoặc sử dụng lọ cookie nào hoặc gửi cookie nào. Loại
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
06DefaultNoneConstant
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
07

Bạn phải chỉ định tùy chọn cookie là

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
06 hoặc
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
3

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
2

Cảnh báo

Tùy chọn này chỉ có tác dụng nếu trình xử lý của bạn có phần mềm trung gian

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
10. Phần mềm trung gian này được thêm theo mặc định khi ứng dụng khách được tạo không có trình xử lý và được thêm theo mặc định khi tạo trình xử lý có ____

Mẹo

Khi tạo ứng dụng khách, bạn có thể đặt tùy chọn cookie mặc định thành

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
4 để sử dụng phiên cookie được chia sẻ được liên kết với ứng dụng khách

connect_timeout¶

SummaryFloat mô tả số giây phải đợi trong khi cố gắng kết nối với máy chủ. Sử dụng
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
13 để đợi vô thời hạn [hành vi mặc định]. TypefloatDefault
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
13Constant
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
15

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
3

Ghi chú

Cài đặt này phải được hỗ trợ bởi trình xử lý HTTP được sử dụng để gửi yêu cầu.

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
16 hiện chỉ được hỗ trợ bởi trình xử lý cURL tích hợp

gỡ lỗi¶

Tóm lược

Đặt thành

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
4 hoặc đặt thành luồng PHP được trả về bởi
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
37 để bật đầu ra gỡ lỗi với trình xử lý được sử dụng để gửi yêu cầu. Ví dụ: khi sử dụng cURL để chuyển yêu cầu, đoạn dài của cURL là
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
19 sẽ được phát ra. Khi sử dụng trình bao bọc luồng PHP, các thông báo về trình bao bọc luồng sẽ được phát ra. Nếu được đặt thành true, đầu ra được ghi vào STDOUT của PHP. Nếu một luồng PHP được cung cấp, đầu ra được ghi vào luồng

các loại
  • bool
  • tài nguyên
    [
        'max'             => 5,
        'strict'          => false,
        'referer'         => false,
        'protocols'       => ['http', 'https'],
        'track_redirects' => false
    ]
    
    37
Mặc định

Không có

Hằng số

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
61

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
4

Chạy ví dụ trên sẽ xuất ra kết quả như sau

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
5

giải mã nội dung¶

Tóm lược

Chỉ định có hay không phản hồi

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
62 [gzip, giảm tốc, v.v. ] được tự động giải mã

các loại
  • chuỗi
  • bool
Mặc định

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
4

Hằng số

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
64

Tùy chọn này có thể được sử dụng để kiểm soát cách xử lý nội dung phản hồi được mã hóa nội dung. Theo mặc định,

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
65 được đặt thành true, nghĩa là mọi phản hồi được nén hoặc giảm tốc sẽ được giải mã bởi Guzzle

Khi được đặt thành

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
3, nội dung của phản hồi không bao giờ được giải mã, nghĩa là các byte đi qua trình xử lý không thay đổi

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
6

Khi được đặt thành chuỗi, các byte của phản hồi được giải mã và giá trị chuỗi được cung cấp cho tùy chọn

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
65 được chuyển dưới dạng tiêu đề
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
68 của yêu cầu

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
7

sự chậm trễ¶

Tóm lược

Số mili giây để trì hoãn trước khi gửi yêu cầu

các loại
  • số nguyên
  • trôi nổi
Mặc định

vô giá trị

Hằng số

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
69

chờ đợi¶

Tóm lược

Kiểm soát hành vi của "Expect. tiêu đề 100-Tiếp tục"

các loại
  • bool
  • số nguyên
Mặc định

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
80

Hằng số

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
81

Đặt thành

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
4 để bật tùy chọn "Mong đợi. 100-Continue" cho tất cả các yêu cầu gửi nội dung. Đặt thành
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
3 để tắt tùy chọn "Mong đợi. tiêu đề 100-Continue" cho tất cả các yêu cầu. Đặt thành một số sao cho kích thước của tải trọng phải lớn hơn số để gửi tiêu đề Kỳ vọng. Đặt thành một số sẽ gửi tiêu đề Kỳ vọng cho tất cả các yêu cầu trong đó kích thước của tải trọng không thể xác định được hoặc khi phần thân không thể tua lại

Theo mặc định, Guzzle sẽ thêm dòng "Expect. 100-Continue" khi kích thước nội dung của yêu cầu lớn hơn 1 MB và yêu cầu đang sử dụng HTTP/1. 1

Ghi chú

Tùy chọn này chỉ có hiệu lực khi sử dụng HTTP/1. 1. HTTP/1. 0 và HTTP/2. 0 không hỗ trợ tùy chọn "Mong đợi. tiêu đề 100-Tiếp tục". Hỗ trợ xử lý lỗi "Mong đợi. Quy trình làm việc 100-Continue" phải được triển khai bởi trình xử lý Guzzle HTTP được khách hàng sử dụng

force_ip_resolve¶

Tóm tắtĐặt thành "v4" nếu bạn muốn trình xử lý HTTP chỉ sử dụng giao thức ipv4 hoặc "v6" cho giao thức ipv6. TypestringDefaultnullConstant
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
84

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
8

Ghi chú

Cài đặt này phải được hỗ trợ bởi trình xử lý HTTP được sử dụng để gửi yêu cầu.

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
85 hiện chỉ được hỗ trợ bởi trình xử lý luồng và cURL tích hợp

form_params¶

Tóm tắtĐược sử dụng để gửi yêu cầu POST ứng dụng/x-www-form-urlencoded. TypearrayConstant
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
86

Mảng liên kết của tên trường biểu mẫu với giá trị trong đó mỗi giá trị là một chuỗi hoặc mảng chuỗi. Đặt tiêu đề Loại nội dung thành ứng dụng/x-www-form-urlencoded khi chưa có tiêu đề Loại nội dung

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
9

Ghi chú

Không thể sử dụng

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
02 với tùy chọn
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
03. Bạn sẽ cần phải sử dụng cái này hay cái kia. Sử dụng
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
02 cho yêu cầu
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
00 và
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
03 cho yêu cầu
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
02

Không thể sử dụng tùy chọn này với

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
36,
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
03 hoặc
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
04

tiêu đề¶

Mảng tiêu đề SummaryAssociative để thêm vào yêu cầu. Mỗi khóa là tên của tiêu đề và mỗi giá trị là một chuỗi hoặc mảng chuỗi đại diện cho các giá trị trường tiêu đề. TypearrayDefaultsNoneConstant
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
06

$res = $client->request['GET', '/redirect/3', ['allow_redirects' => false]];
echo $res->getStatusCode[];
// 302
0

Tiêu đề có thể được thêm làm tùy chọn mặc định khi tạo ứng dụng khách. Khi tiêu đề được sử dụng làm tùy chọn mặc định, chúng chỉ được áp dụng nếu yêu cầu được tạo chưa chứa tiêu đề cụ thể. Điều này bao gồm cả các yêu cầu được chuyển đến máy khách theo phương pháp

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
07 và
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
08 và các yêu cầu do máy khách tạo ra [e. g. ,
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
09 và
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
10]

$res = $client->request['GET', '/redirect/3', ['allow_redirects' => false]];
echo $res->getStatusCode[];
// 302
1

http_errors¶

Tóm tắtĐặt thành
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
3 để vô hiệu hóa các ngoại lệ đối với lỗi giao thức HTTP [i. e. , phản hồi 4xx và 5xx]. Các ngoại lệ được đưa ra theo mặc định khi gặp lỗi giao thức HTTP. TypeboolDefault
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
4Constant
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
13

$res = $client->request['GET', '/redirect/3', ['allow_redirects' => false]];
echo $res->getStatusCode[];
// 302
2

Cảnh báo

Tùy chọn này chỉ có tác dụng nếu trình xử lý của bạn có phần mềm trung gian

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
14. Phần mềm trung gian này được thêm theo mặc định khi ứng dụng khách được tạo không có trình xử lý và được thêm theo mặc định khi tạo trình xử lý có ____

idn_conversion¶

Tóm lược

Hỗ trợ tên miền quốc tế hóa [IDN] [được bật theo mặc định nếu có tiện ích mở rộng

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
16]

các loại
  • bool
  • int
Mặc định

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
4 nếu có tiện ích mở rộng
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
16 [và thư viện ICU là 4. 6+ cho PHP 7. 2+],
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
3 ngược lại

Hằng số

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
20

$res = $client->request['GET', '/redirect/3', ['allow_redirects' => false]];
echo $res->getStatusCode[];
// 302
3

Bật/tắt hỗ trợ IDN, cũng có thể được sử dụng để kiểm soát chính xác bằng cách kết hợp các hằng số IDNA_* [ngoại trừ IDNA_ERROR_*], xem tham số

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
21 trong tài liệu idn_to_ascii[] để biết thêm chi tiết

json¶

Tóm tắt Tùy chọn ________ 204 được sử dụng để dễ dàng tải lên dữ liệu được mã hóa JSON dưới dạng nội dung của yêu cầu. Tiêu đề Kiểu nội dung của
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
23 sẽ được thêm nếu chưa có tiêu đề Kiểu nội dung nào trên thư. Các loạiBất kỳ loại PHP nào có thể được vận hành bởi hàm
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
24 của PHP. Mặc địnhNoneConstant
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
25

$res = $client->request['GET', '/redirect/3', ['allow_redirects' => false]];
echo $res->getStatusCode[];
// 302
4

Đây là một ví dụ về việc sử dụng phần mềm trung gian

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
26 để xem yêu cầu nào được gửi qua dây

$res = $client->request['GET', '/redirect/3', ['allow_redirects' => false]];
echo $res->getStatusCode[];
// 302
5

Ghi chú

Tùy chọn yêu cầu này không hỗ trợ tùy chỉnh tiêu đề Loại nội dung hoặc bất kỳ tùy chọn nào từ hàm json_encode[] của PHP. Nếu bạn cần tùy chỉnh các cài đặt này, thì bạn phải tự chuyển dữ liệu được mã hóa JSON vào yêu cầu bằng cách sử dụng tùy chọn yêu cầu

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
36 và bạn phải chỉ định tiêu đề Loại nội dung chính xác bằng cách sử dụng tùy chọn yêu cầu
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
28

Không thể sử dụng tùy chọn này với

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
36,
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
02 hoặc
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
03

nhiều phần¶

Tóm tắtĐặt nội dung của yêu cầu thành biểu mẫu nhiều phần/biểu mẫu dữ liệu. TypearrayConstant
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
32

Giá trị của

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
03 là một mảng gồm các mảng kết hợp, mỗi mảng chứa các cặp giá trị khóa sau

  • [
        'max'             => 5,
        'strict'          => false,
        'referer'         => false,
        'protocols'       => ['http', 'https'],
        'track_redirects' => false
    ]
    
    34. [chuỗi, bắt buộc] tên trường biểu mẫu
  • [
        'max'             => 5,
        'strict'          => false,
        'referer'         => false,
        'protocols'       => ['http', 'https'],
        'track_redirects' => false
    ]
    
    35. [StreamInterface/resource/string, bắt buộc] Dữ liệu để sử dụng trong phần tử biểu mẫu
  • [
        'max'             => 5,
        'strict'          => false,
        'referer'         => false,
        'protocols'       => ['http', 'https'],
        'track_redirects' => false
    ]
    
    28. [mảng] Mảng kết hợp tùy chọn của các tiêu đề tùy chỉnh để sử dụng với phần tử biểu mẫu
  • [
        'max'             => 5,
        'strict'          => false,
        'referer'         => false,
        'protocols'       => ['http', 'https'],
        'track_redirects' => false
    ]
    
    37. [chuỗi] Chuỗi tùy chọn để gửi dưới dạng tên tệp trong phần

$res = $client->request['GET', '/redirect/3', ['allow_redirects' => false]];
echo $res->getStatusCode[];
// 302
6

Ghi chú

Không thể sử dụng

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
03 với tùy chọn
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
02. Bạn sẽ cần phải sử dụng cái này hay cái kia. Sử dụng
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
02 cho yêu cầu
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
00 và
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
03 cho yêu cầu
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
02

Không thể sử dụng tùy chọn này với

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
36,
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
02 hoặc
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
04

on_headers¶

Tóm lược

Có thể gọi được gọi khi đã nhận được các tiêu đề HTTP của phản hồi nhưng phần thân chưa bắt đầu tải xuống

các loại
  • gọi được
Hằng số

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
47

Có thể gọi được chấp nhận một đối tượng

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
48. Nếu một ngoại lệ được ném bởi khả năng gọi được, thì lời hứa liên quan đến phản hồi sẽ bị từ chối với một
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
49 bao bọc ngoại lệ đã được ném

Bạn có thể cần biết những tiêu đề và mã trạng thái nào đã được nhận trước khi dữ liệu có thể được ghi vào phần chìm

$res = $client->request['GET', '/redirect/3', ['allow_redirects' => false]];
echo $res->getStatusCode[];
// 302
7

Ghi chú

Khi viết trình xử lý HTTP, hàm

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
50 phải được gọi trước khi ghi dữ liệu vào phần thân của phản hồi

on_stats¶

Tóm lược

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
51 cho phép bạn có quyền truy cập vào số liệu thống kê chuyển yêu cầu và truy cập chi tiết chuyển cấp thấp hơn của trình xử lý được liên kết với khách hàng của bạn.
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
51 là một khả năng gọi được gọi khi trình xử lý gửi yêu cầu xong. Cuộc gọi lại được gọi với số liệu thống kê chuyển về yêu cầu, phản hồi nhận được hoặc lỗi gặp phải. Bao gồm trong dữ liệu là tổng thời gian cần thiết để gửi yêu cầu

các loại
  • gọi được
Hằng số

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
53

Callable chấp nhận một đối tượng

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
54

$res = $client->request['GET', '/redirect/3', ['allow_redirects' => false]];
echo $res->getStatusCode[];
// 302
8

phát triển¶

Tóm lược

Xác định một chức năng để gọi khi tiến trình chuyển giao được thực hiện

các loại
  • gọi được
Mặc định

Không có

Hằng số

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
55

Hàm chấp nhận các đối số vị trí sau

  • tổng số byte dự kiến ​​sẽ được tải xuống, 0 nếu không xác định
  • số lượng byte được tải xuống cho đến nay
  • tổng số byte dự kiến ​​sẽ được tải lên
  • số lượng byte được tải lên cho đến nay

$res = $client->request['GET', '/redirect/3', ['allow_redirects' => false]];
echo $res->getStatusCode[];
// 302
9

Ủy quyền¶

Tóm lược

Truyền một chuỗi để chỉ định proxy HTTP hoặc một mảng để chỉ định các proxy khác nhau cho các giao thức khác nhau

các loại
  • chuỗi
  • mảng
Mặc định

Không có

Hằng số

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
56

Truyền một chuỗi để chỉ định proxy cho tất cả các giao thức

$res = $client->request['GET', '/redirect/3'];
echo $res->getStatusCode[];
// 200
0

Truyền một mảng kết hợp để chỉ định proxy HTTP cho các lược đồ URI cụ thể [i. e. , "http", "https"]. Cung cấp một cặp giá trị khóa

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
57 để cung cấp danh sách các tên máy chủ lưu trữ không được ủy quyền cho

Ghi chú

Guzzle sẽ tự động điền giá trị này với biến môi trường

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
58 của môi trường của bạn. Tuy nhiên, khi cung cấp tùy chọn yêu cầu
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
59, bạn phải cung cấp giá trị
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
57 được phân tích cú pháp từ biến môi trường
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
58 [e. g. ,
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
62]

$res = $client->request['GET', '/redirect/3'];
echo $res->getStatusCode[];
// 200
1

Ghi chú

Bạn có thể cung cấp các URL proxy chứa lược đồ, tên người dùng và mật khẩu. Ví dụ,

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
63

truy vấn¶

Tóm lược

Mảng kết hợp của các giá trị chuỗi truy vấn hoặc chuỗi truy vấn để thêm vào yêu cầu

các loại
  • mảng
  • chuỗi
Mặc định

Không có

Hằng số

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
64

$res = $client->request['GET', '/redirect/3'];
echo $res->getStatusCode[];
// 200
2

Các chuỗi truy vấn được chỉ định trong tùy chọn

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
65 sẽ ghi đè lên tất cả các giá trị chuỗi truy vấn được cung cấp trong URI của một yêu cầu

$res = $client->request['GET', '/redirect/3'];
echo $res->getStatusCode[];
// 200
3

giờ đọc đã kết thúc¶

SummaryFloat mô tả thời gian chờ sẽ sử dụng khi đọc bodyTypesfloatDefaultDefaults được truyền trực tuyến thành giá trị của cài đặt ini
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
66 PHPConstant
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
67

Thời gian chờ áp dụng cho các thao tác đọc riêng lẻ trên nội dung được phát trực tuyến [khi tùy chọn

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
68 được bật]

$res = $client->request['GET', '/redirect/3'];
echo $res->getStatusCode[];
// 200
4

bồn rửa chén¶

Tóm lược

Chỉ định nơi nội dung của phản hồi sẽ được lưu

các loại
  • chuỗi [đường dẫn đến tệp trên đĩa]
  • tài nguyên
    [
        'max'             => 5,
        'strict'          => false,
        'referer'         => false,
        'protocols'       => ['http', 'https'],
        'track_redirects' => false
    ]
    
    37
  • [
        'max'             => 5,
        'strict'          => false,
        'referer'         => false,
        'protocols'       => ['http', 'https'],
        'track_redirects' => false
    ]
    
    38
Mặc định

Luồng tạm thời PHP

Hằng số

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
71

Truyền một chuỗi để chỉ định đường dẫn đến tệp sẽ lưu trữ nội dung của nội dung phản hồi

$res = $client->request['GET', '/redirect/3'];
echo $res->getStatusCode[];
// 200
5

Truyền tài nguyên được trả về từ

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
37 để viết phản hồi cho luồng PHP

$res = $client->request['GET', '/redirect/3'];
echo $res->getStatusCode[];
// 200
6

Truyền một đối tượng

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
38 để truyền nội dung phản hồi tới luồng PSR-7 đang mở

$res = $client->request['GET', '/redirect/3'];
echo $res->getStatusCode[];
// 200
7

Ghi chú

Tùy chọn yêu cầu

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
74 không được dùng nữa để thay thế cho tùy chọn yêu cầu
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
75. Cung cấp tùy chọn
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
74 hiện là bí danh của
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
75

ssl_key¶

Tóm lược

Chỉ định đường dẫn đến tệp chứa khóa SSL riêng ở định dạng PEM. Nếu mật khẩu được yêu cầu, thì hãy đặt thành một mảng chứa đường dẫn đến khóa SSL trong phần tử mảng đầu tiên, sau đó là mật khẩu cần thiết cho chứng chỉ trong phần tử thứ hai

các loại
  • chuỗi
  • mảng
Mặc định

Không có

Hằng số

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
78

Ghi chú

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
79 được triển khai bởi trình xử lý HTTP. Điều này hiện chỉ được hỗ trợ bởi trình xử lý cURL, nhưng có thể được hỗ trợ bởi các trình xử lý bên thứ ba khác

dòng¶

Tóm tắtĐặt thành
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
4 để truyền phản hồi thay vì tải xuống tất cả phản hồi từ trước. TypeboolDefault
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
3Constant
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
82

$res = $client->request['GET', '/redirect/3'];
echo $res->getStatusCode[];
// 200
8

Ghi chú

Hỗ trợ phản hồi trực tuyến phải được triển khai bởi trình xử lý HTTP được khách hàng sử dụng. Tùy chọn này có thể không được hỗ trợ bởi mọi trình xử lý HTTP, nhưng giao diện của đối tượng phản hồi vẫn giữ nguyên bất kể nó có được trình xử lý hỗ trợ hay không

đồng bộ¶

Tóm tắtĐặt thành true để thông báo cho trình xử lý HTTP rằng bạn dự định chờ phản hồi. Điều này có thể hữu ích cho việc tối ưu hóa. TypeboolDefaultnoneConstant
[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
83

thẩm tra¶

Tóm lược

Mô tả hành vi xác minh chứng chỉ SSL của một yêu cầu

  • Đặt thành
    use Psr\Http\Message\RequestInterface;
    use Psr\Http\Message\ResponseInterface;
    use Psr\Http\Message\UriInterface;
    
    $onRedirect = function[
        RequestInterface $request,
        ResponseInterface $response,
        UriInterface $uri
    ] {
        echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
    };
    
    $res = $client->request['GET', '/redirect/3', [
        'allow_redirects' => [
            'max'             => 10,        // allow at most 10 redirects.
            'strict'          => true,      // use "strict" RFC compliant redirects.
            'referer'         => true,      // add a Referer header
            'protocols'       => ['https'], // only allow https URLs
            'on_redirect'     => $onRedirect,
            'track_redirects' => true
        ]
    ]];
    
    echo $res->getStatusCode[];
    // 200
    
    echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
    // //first-redirect, //second-redirect, etc...
    
    echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
    // 301, 302, etc...
    
    4 để bật xác minh chứng chỉ SSL và sử dụng gói CA mặc định do hệ điều hành cung cấp
  • Đặt thành
    use Psr\Http\Message\RequestInterface;
    use Psr\Http\Message\ResponseInterface;
    use Psr\Http\Message\UriInterface;
    
    $onRedirect = function[
        RequestInterface $request,
        ResponseInterface $response,
        UriInterface $uri
    ] {
        echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
    };
    
    $res = $client->request['GET', '/redirect/3', [
        'allow_redirects' => [
            'max'             => 10,        // allow at most 10 redirects.
            'strict'          => true,      // use "strict" RFC compliant redirects.
            'referer'         => true,      // add a Referer header
            'protocols'       => ['https'], // only allow https URLs
            'on_redirect'     => $onRedirect,
            'track_redirects' => true
        ]
    ]];
    
    echo $res->getStatusCode[];
    // 200
    
    echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
    // //first-redirect, //second-redirect, etc...
    
    echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
    // 301, 302, etc...
    
    3 để tắt xác minh chứng chỉ [điều này không an toàn. ]
  • Đặt thành chuỗi để cung cấp đường dẫn đến gói CA nhằm bật xác minh bằng chứng chỉ tùy chỉnh
các loại
  • bool
  • chuỗi
Mặc định

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

$onRedirect = function[
    RequestInterface $request,
    ResponseInterface $response,
    UriInterface $uri
] {
    echo 'Redirecting! ' . $request->getUri[] . ' to ' . $uri . "\n";
};

$res = $client->request['GET', '/redirect/3', [
    'allow_redirects' => [
        'max'             => 10,        // allow at most 10 redirects.
        'strict'          => true,      // use "strict" RFC compliant redirects.
        'referer'         => true,      // add a Referer header
        'protocols'       => ['https'], // only allow https URLs
        'on_redirect'     => $onRedirect,
        'track_redirects' => true
    ]
]];

echo $res->getStatusCode[];
// 200

echo $res->getHeaderLine['X-Guzzle-Redirect-History'];
// //first-redirect, //second-redirect, etc...

echo $res->getHeaderLine['X-Guzzle-Redirect-Status-History'];
// 301, 302, etc...
4

Hằng số

[
    'max'             => 5,
    'strict'          => false,
    'referer'         => false,
    'protocols'       => ['http', 'https'],
    'track_redirects' => false
]
87

$res = $client->request['GET', '/redirect/3'];
echo $res->getStatusCode[];
// 200
9

Nếu bạn không cần gói chứng chỉ cụ thể, thì Mozilla cung cấp gói CA thường được sử dụng có thể tải xuống tại đây [do nhà cung cấp cURL cung cấp]. Khi bạn có gói CA sẵn có trên đĩa, bạn có thể đặt "openssl. cafile" PHP ini để trỏ đến đường dẫn đến tệp, cho phép bạn bỏ qua tùy chọn yêu cầu "xác minh". Bạn có thể tìm thấy nhiều chi tiết hơn về chứng chỉ SSL trên trang web cURL

Làm cách nào để lấy dữ liệu từ yêu cầu trong PHP?

PHP $_GET . PHP $_GET là một biến siêu toàn cầu PHP được sử dụng để thu thập dữ liệu biểu mẫu sau khi gửi biểu mẫu HTML với method="get". $_GET cũng có thể thu thập dữ liệu được gửi trong URL.

Làm cách nào để kiểm tra yêu cầu đăng trong PHP?

Trong PHP, chúng ta có thể sử dụng phương thức $_POST như một biến siêu toàn cục được vận hành để quản lý dữ liệu biểu mẫu . Sau khi chúng tôi nhấp vào nút gửi và trang sẽ gửi dữ liệu qua phương thức đăng.

Tải trọng trong PHP là gì?

Hào khí. Khối hàng. Bạn sử dụng Tải trọng làm đối tượng truyền dữ liệu để gửi kết quả lớp miền đến lớp giao diện người dùng của bạn, cùng với siêu dữ liệu cho biết ý nghĩa của kết quả miền.

Tải trọng của một yêu cầu là gì?

Tải trọng của một yêu cầu hoặc phản hồi HTTP bao gồm Thông tin giao thức HTTP như tiêu đề, URL, nội dung cơ thể cũng như thông tin về phiên bản và trạng thái.

Chủ Đề