gpt4 book ai didi

authentication - 通过 curl 登录到 stackoverflow.com

转载 作者:行者123 更新时间:2023-12-04 04:40:31 25 4
gpt4 key购买 nike

我正在尝试以编程方式登录我的 stackoverflow.com 帐户。我试图做一个像下面这样的 curl ,但它要求内容长度:

$ curl -X POST --user abc@gmail.com:abc https://stackoverflow.com/users/login -v
* Trying 151.101.193.69...
* Connected to stackoverflow.com (151.101.193.69) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: *.stackexchange.com
* Server certificate: DigiCert SHA2 High Assurance Server CA
* Server certificate: DigiCert High Assurance EV Root CA
* Server auth using Basic with user 'abc@gmail.com'
> POST /users/login HTTP/1.1
> Host: stackoverflow.com
> Authorization: Basic YWJjQGdtYWlsLmNvbTphYmM=
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Type:application/json
>
< HTTP/1.1 411 Length Required
< Content-Type: text/html; charset=us-ascii
< Content-Length: 344
< Accept-Ranges: bytes
< Date: Sat, 10 Sep 2016 14:51:27 GMT
< Via: 1.1 varnish
< Connection: keep-alive
< X-Served-By: cache-sin6924-SIN
< X-Cache: MISS
< X-Cache-Hits: 0
< X-Timer: S1473519087.232710,VS0,VE240
< X-DNS-Prefetch-Control: off
< Set-Cookie: prov=b46dabec-5ba0-92ef-b6dd-884666bea467; domain=.stackoverflow.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; path=/; HttpOnly
<
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Length Required</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Length Required</h2>
<hr><p>HTTP Error 411. The request must be chunked or have a content length.</p>
</BODY></HTML>
* Connection #0 to host stackoverflow.com left intact

我也试过没有 POST .它返回 200 但没有登录。
$ curl --user abc@gmail.com:abc  https://stackoverflow.com/users/login -v
* Trying 151.101.193.69...
* Connected to stackoverflow.com (151.101.193.69) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: *.stackexchange.com
* Server certificate: DigiCert SHA2 High Assurance Server CA
* Server certificate: DigiCert High Assurance EV Root CA
* Server auth using Basic with user 'abc@gmail.com'
> GET /users/login HTTP/1.1
> Host: stackoverflow.com
> Authorization: Basic YWJjQGdtYWlsLmNvbTphYmM=
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Cache-Control: private
< Content-Type: text/html; charset=utf-8
< X-Frame-Options: SAMEORIGIN
< X-Request-Guid: cb0c93fa-9a05-4661-bc34-c4d97225b13e
< Content-Length: 37753
< Accept-Ranges: bytes
< Date: Sat, 10 Sep 2016 14:53:41 GMT
< Via: 1.1 varnish
< Age: 0
< Connection: keep-alive
< X-Served-By: cache-sin6924-SIN
< X-Cache: MISS
< X-Cache-Hits: 0
< X-Timer: S1473519220.936412,VS0,VE257
< X-DNS-Prefetch-Control: off

我怎样才能做到这一点?

最佳答案

除此之外,使用 api.stackexchange.com/docs/authentication 将是最好的解决方案,您对上述 curl 语句的问题是您向服务器发送了一个没有正文的 http 帖子。所以你应该添加如下内容:

-d "user=value1&passwd=value2"

此处 user/passwd 应该是登录对话框的字段名称 - 也可能登录表单包含一些隐藏字段......所以你应该首先分析它。
还要记住,您让 curl 将 cookie 写入文件,以便您可以在以后的 curl 调用中使用它们。

关于authentication - 通过 curl 登录到 stackoverflow.com,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39427269/

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