簡體   English   中英

HTTP 通過身份驗證獲取請求 header groovy

[英]HTTP Get request with Authentication header groovy

我正在嘗試向 URL 發出 HTTP 獲取請求。 我已經嘗試過 curl 命令,它適用於我的身份驗證,但在 groovy 腳本中,我得到了 NULL 響應。

import org.apache.commons.httpclient.HttpClient
import org.apache.commons.httpclient.methods.GetMethod

def http = new HttpClient();
def get = new GetMethod("https://tect-hello/cit");
def requestHeader=get.setRequestHeader("X-Vault-Token","s.mytoken");
println requestHeader             //NULL
println get.getName();            //GET
println get.getResponseBody()     //NULL

CURL 命令

curl -H "X-Vault-Token: s.mytoken" -X GET https://tect-hello/cit

我嘗試了發布功能並且它有效。

我無法找到傳遞保險庫令牌的方法。 我嘗試了addRequestHeadersetRequestHeader

所以我找到了如何做get方法。

def get = new GetMethod("URL")
get.setRequestHeader("X-Vault-Token","s.mytoken")
println http.executeMethod(get) // This step is important
println get.getResponseBodyAsString(1000)

希望這對某人有幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM