亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

來自 GuzzleHttp 響應的 URI

來自 GuzzleHttp 響應的 URI

PHP
陪伴而非守候 2023-09-15 21:44:34
URI我需要從當前使用的Response中獲取,并同時處理至少 50 個項目,并且需要一種方法來從 guzzle 中獲取我使用的。GuzzleHTTPgetAsyncURIClient$groups->each(function($group) {    $promises = $group->map( function($lead, $index) {        $client = new Client(['http_errors' => false]);        return $client->getAsync($lead->website, [            'timeout' => 5, // Response timeout            'connect_timeout' => 5, // Connection timeout        ]);     })->toArray();    settle($promises)->then( function($results) {        $collections = collect($results);        $fulfilled = $collections->where('state', 'fulfilled')->all();    })->wait();});似乎Request有這個getUri方法,但Response在接口或類和文檔中沒有也找不到。希望有人可以提供幫助編輯:嘗試過getEffectiveUrl,但這僅適用于 Guzzle 5,目前使用 6
查看完整描述

1 回答

?
慕蓋茨4494581

TA貢獻1850條經驗 獲得超11個贊

這是給guzzle 5用的


在響應中,您沒有 getUri 方法,因為只有請求有此方法。


如果發生重定向或發生某些情況,您可以使用以下方法獲取響應 url


$response = GuzzleHttp\get('http://httpbin.org/get');

echo $response->getEffectiveUrl();

// http://httpbin.org/get


$response = GuzzleHttp\get('http://httpbin.org/redirect-to?url=http://www.google.com');

echo $response->getEffectiveUrl();

// http://www.google.com


use GuzzleHttp\Client;

use GuzzleHttp\TransferStats;


$client = new Client;


$client->get('http://some.site.com', [

? ? 'query'? ?=> ['get' => 'params'],

? ? 'on_stats' => function (TransferStats $stats) use (&$url) {

? ? ? ? $url = $stats->getEffectiveUri();

? ? }

])->getBody()->getContents();


echo $url; // http://some.site.com?get=params

查看完整回答
反對 回復 2023-09-15
  • 1 回答
  • 0 關注
  • 163 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號