2016-11-03 2 views
0

API 끝점 List Users에 대한 Okta의 페이지 매김을 구현하려고합니다. 페이지 매김을하기 위해서는 다음과 같은 링크가 수신 헤더에서 수신되어야합니다. 명령 줄의 cUrl 또는 Postman을 통해 List Users API 끝점을 실행할 때 헤더에서 모든 것이 잘 보이지만 문제는 cUrl 또는 guzzle을 사용하는 PHP 스크립트에서 실행하는 경우 링크 html 태그가 다음과 같이 헤더에서 제거됩니다. 아래 : 나는 잠시 동안 검색하고 해결책을 찾을 수 없습니다페이지 매김시 Okta의 API 목록 사용자의 응답 헤더에서 다음 링크를 얻으려면 어떻게해야합니까?

HTTP/1.1 200 OK 
Content-Type: application/json 
Link: <https://your-domain.okta.com/api/v1/users?limit=200>; rel="self" 
Link: <https://your-domain.okta.com/api/v1/users? after=00ud4tVDDXYVKPXKVLCO&limit=200>; rel="next" 

:로

HTTP/1.1 200 OK 
Date: Thu, 03 Nov 2016 19:36:34 GMT 
Server: nginx 
Content-Type: application/json;charset=UTF-8 
Vary: Accept-Encoding 
X-Okta-Request-Id: WBuTwqhxlYz3iu5PY1jqHQZZBMU 
X-Rate-Limit-Limit: 1200 
X-Rate-Limit-Remaining: 1198 
X-Rate-Limit-Reset: 1478201841 
Cache-Control: no-cache, no-store 
Pragma: no-cache 
Expires: 0 
Link: ; rel="self" 
Strict-Transport-Security: max-age=315360000 

헤더는해야한다 대신 보인다. 이전에이 문제를 접한 사람이 있습니까? 미리 감사드립니다.

답변

2

귀하의 요청에 Accept: application/json 헤더가 포함되어 있는지 확인하십시오. 내 생각에 PHP의 cURL이나 Guzzle은 text/plain과 같은 다른 MIME 유형을 사용하고 있습니다.

curl --verbose \ 
     --header "Authorization: SSWS ${API_KEY}" \ 
     --header "Content-Type: application/json" \ 
     --header "Accept: application/json" \ 
     "https://${ORG}/api/v1/users?limit=1" 2>&1 | grep 'Link: ' 

< Link: <https://example.okta.com/api/v1/users?limit=1>; rel="self" 
< Link: <https://example.okta.com/api/v1/users?after=012a3b456cdefgHijK7l8&limit=1>; rel="next" 
: 나는 application/jsonAccept: 헤더를 변경하면 나는 Link: 헤더를받을 수 있나요,

curl --verbose \ 
     --header "Authorization: SSWS ${API_KEY}" \ 
     --header "Content-Type: application/json" \ 
     --header "Accept: text/plain" \ 
     "https://${ORG}/api/v1/users?limit=1" 2>&1 | grep 'Link: ' 

그러나 :

나는 어떤 결과를 제공하지 않는 다음 curl 명령을 사용하여 문제를 재현 할 수 있었다
+0

답장을 보내 주셔서 감사합니다. 그래서 내 경우처럼, 우리는 어떤 이유로이 함수는 헤더에서 링크의 내용을 스트립 헤더를 인쇄하려면 PHP의 print_r()를 사용했다. 헤더의 MIME 유형에 대해 옳았습니다. 다시 한 번 감사드립니다! – user1370897

0

다른 게시물을 검색하는 동안 내 게시물을 발견했습니다. 최근이 문제를 해결했으며 이것이 내 솔루션입니다. 이 모든 것은 PowerShell로 작성되었습니다.

#Function to automatically get all listings by pagination, this function will use the default Okta Limit parameter. Which is 1000 as the time of this making. 
#Invoke-OktaPagedMethod is based on the _oktaRecGet() function from https://github.com/mbegan/Okta-PSModule/blob/master/Okta.psm1 
function Invoke-OktaPagedMethod { 
    param 
    (
     [string]$Uri, 
     [array]$col, 
     [int]$loopcount = 0 
    ) 

    try { 
     #[System.Net.HttpWebResponse]$response = $request.GetResponse() 
     $OktaResponse = Invoke-WebRequest -Method Get -UseBasicParsing -Uri $Uri -Headers $OktaHeaders -TimeoutSec 300 

     #Build an Hashtable to store the links 
     $link = @{} 
     if ($OktaResponse.Headers.Link) { # Some searches (eg List Users with Search) do not support pagination. 
      foreach ($header in $OktaResponse.Headers.Link.split(",")) { 
       if ($header -match '<(.*)>; rel="(.*)"') { 
        $link[$matches[2]] = $matches[1] 
       } 
      } 
     } 

     $link = @{ 
      next = $link.next 
     } 

     try { 
      $psobj = ConvertFrom-Json -InputObject $OktaResponse.Content 
      $col = $col + $psobj 
     } catch { 
      throw "Json Exception : " + $OktaResponse 
     } 
    } catch { 
     throw $_ 
    } 

    if ($link.next) { 
     $loopcount++ 
     if ($oktaVerbose) { Write-Host "fetching next page $loopcount : " -ForegroundColor Cyan} 
     Invoke-OktaPagedMethod -Uri $link.next -col $col -loopcount $loopcount 
    } else { 
     return $col 
    } 
} 
관련 문제