gpt4 book ai didi

http - 我在使用 wget 时收到 cookie,但在使用 groovy 脚本时没有收到 cookie

转载 作者:可可西里 更新时间:2023-11-01 17:34:20 24 4
gpt4 key购买 nike

这是 wget 命令:

wget --auth-no-challenge --http-user=auth_user --http-password=auth_pass --save-cookies cookies.txt --keep-session-cookies --post-data 'user_login=username&pass=password' https://www.helloworld.com/login.php

这是常规脚本:

static List<String> login(String baseUrl, String path, query, method = Method.POST) {
try {
def ret = null
def http = new HTTPBuilder(baseUrl)

http.request(method, ContentType.URLENC) {
uri.path = path
uri.query = query

headers.'Authorization' = "Basic ${"auth_user:auth_pass".bytes.encodeBase64().toString()}"

// response handler for a success response code
response.success = { resp, data ->

println "response status: ${resp.statusLine}"

resp.getHeaders('Set-Cookie').each {

def cookie = it.value.split(";").toString()
println cookie
.add(cookie)
}
println 'Response : ' + resp.getData()
}
}
return cookies

} catch (groovyx.net.http.HttpResponseException ex) {
ex.printStackTrace()

} catch (java.net.ConnectException ex) {
ex.printStackTrace()

}
}

def url = "https://www.helloworld.com/login.php"
def path = ""
def query = [ user_login: "username@calypso", pass: "password" ]

// Submit a request via POST
def response = login(url, path, query)

所以 wget 命令为我获取了 cookie,但这个 groovy 脚本没有。这是我得到的回应:

response status: HTTP/1.1 200 OK
Header:
Date : Mon, 28 Mar 2016 19:56:20 GMT
Server : Apache/2.2.3 (CentOS)
Last-Modified : Sat, 03 May 2003 21:37:01 GMT
ETag : "56b0013-1d4-3bcc9546cd940"
Accept-Ranges : bytes
Content-Length : 468
Keep-Alive : timeout=999
Connection : Keep-Alive
Content-Type : text/html; charset=UTF-8

最佳答案

您可能不应该自己进行身份验证。如果仅成功的身份验证创建一个 cookie,这就可以解释这种现象。

尝试

def http = new HTTPBuilder(baseUrl)
http.auth.basic 'auth_user', 'auth_pass'

另见 documentation .此外,非空响应主体可能会提示您出了什么问题。

关于http - 我在使用 wget 时收到 cookie,但在使用 groovy 脚本时没有收到 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36270260/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com