2019-04-01 17:40
浏览 91

php Curl在标题中获取JWT

I have a rest request, I used curl for php but I need to get the response JWT that comes in the headers to make a new request signed by JWT without needing to re-login. every time I make a request the API returns a new JWT to do another but I do not know how to get it from curl, Someone knows how?

图片转代码服务由CSDN问答提供 功能建议

我有一个休息请求,我使用curl for php但我需要获得标题中的响应JWT 无需重新登录即可通过JWT签署新请求。 每次我发出请求时,API都会返回一个新的JWT来执行另一个请求,但我不知道如何从curl中获取它,有人知道怎么做?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doutangdan3588 2019-04-01 18:09

    i need enable CURLOPT_HEADER => true in my array

    打赏 评论
  • dpzo13732 2019-04-01 18:14

    You must know the name of header element, this function returns assoc. array, you must only write the name of your JWT response header.

    $response = curl_exec($ch);
    $headers = get_headers_from_curl_response($response);
    function get_headers_from_curl_response($response)
        $headers = array();
        $header_text = substr($response, 0, strpos($response, "
        foreach (explode("
    ", $header_text) as $i => $line)
            if ($i === 0)
                $headers['http_code'] = $line;
                list ($key, $value) = explode(': ', $line);
                $headers[$key] = $value;
        return $headers;

    This function makes array from CURL response.

    Final variable will be this

    $myJWT = $headers['CUSTOM_HEADER_NAME_OF_JWT'];
    打赏 评论

相关推荐 更多相似问题