国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

【已解決】關(guān)于http-client 摘要認證請求接口的問題(通過二次請求可以實現(xiàn))

Gin

問題描述

curl這樣設(shè)置是可以成功訪問的

截圖

guzzle 也可以

由于 http-client 無法從服務(wù)器獲取 nonce 無法生成 digest http-client 無法完成 摘要認證

有沒有大佬做過 http-client 摘要認證的 給說說

解決方法

實現(xiàn)方式
先通過第一次請求 獲取 返回的頭部信息 WWW-Authenticate 拿到 qop nonce realm 然后通過計算得出 response 然后拼接 請求頭 進行二次請求

    $http->get('http://192.168.100.236:8686/ISAPI/Event/notification/httpHosts?format=json&devIndex=35BEDA2D-ED63-42CD-9A72-5B086AFDAE15',function($response)use($http,$url){
            $header = $response->getHeaders();

            $wwwAuth = $header['WWW-Authenticate'];
            $arr = explode(' ',$wwwAuth[0]);

            $username = "admin";

            $password = "hik123456";
            $realm   = trim(trim(explode('=',$arr[2])[1],','),'"'); //取出逗號及雙引號
            $nonce   = trim(trim(explode('=',$arr[3])[1],','),'"');

            $cnonce = 'apipost';
            $nc = dechex(rand());
            $uri = '/ISAPI/Event/notification/httpHosts?format=json&devIndex=35BEDA2D-ED63-42CD-9A72-5B086AFDAE15';
            $method = 'GET';
            $qop = "auth";

            $A1 = md5($username.":".$realm.":".$password);

            $A2 = md5($method.":".$uri);

            $response3 = md5($A1.":".$nonce.":".$nc.":".$cnonce.':'.$qop.':'.$A2);

            $request = sprintf('Digest username="%s", realm="%s", nonce="%s", uri="%s", algorithm="MD5", qop=%s, nc=%s, cnonce="%s", response="%s", opaque=""', $username, $realm, $nonce, $uri, $qop, $nc,$cnonce, $response3);

            $http->request($url,[
                'method' => 'GET',
                'version' => '1.1',
                'headers' => ['Connection' => 'keep-alive', 'Authorization' => $request],
                //'data' => $data,
                'success' => function ($response2) {
                    echo $response2->getBody();
                },
                'error' => function ($exception) {
                    echo $exception;
                }
            ]);
        }, function($exception){
                echo $exception;
        });
1113 0 1
0個回答

年代過于久遠,無法發(fā)表回答
??