首页 > 解决方案 > 使用 curl 登录 php 站点

问题描述

我正在尝试做一个 bash 脚本来通过 curl 登录到一个 php 站点。通过这种方式(始终使用 curl),我将能够下载文件。

有问题的网站是这样的:

"https://web.spaggiari.eu/home/app/default/login.php"

我想我可以使用这个命令通过发送一个cookie来登录:

curl --anyauth --user username:password https://web.spaggiari.eu/

然后尝试使用此命令从该站点下载文件(下面的站点是我应该从中下载文件的位置):

curl -v https://web.spaggiari.eu/fml/app/default/xml_export.php? 3Aclasse_id% 3A & gruppo_id =% 3Agruppo_id% 3A & ope = RPT & dal = 2020-11-03 & al = 2020-11-03 & format = xls 

该命令的输出是这样的:

* Expire in 2 ms for 1 (transfer 0x558707881f50)
*   Trying 159.69.111.222...
* TCP_NODELAY set
* Expire in 149996 ms for 3 (transfer 0x558707881f50)
* Expire in 200 ms for 4 (transfer 0x558707881f50)
* Connected to web.spaggiari.eu (159.69.111.222) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: CN=*.spaggiari.eu
*  start date: May 29 00:00:00 2020 GMT
*  expire date: May 29 12:00:00 2022 GMT
*  subjectAltName: host "web.spaggiari.eu" matched cert's "*.spaggiari.eu"
*  issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=GeoTrust RSA CA 2018
*  SSL certificate verify ok.
> GET /fml/app/default/xml_export.php?stampa=%3Astampa%3A HTTP/1.1
> Host: web.spaggiari.eu
> User-Agent: curl/7.64.0
> Accept: */*
> 
< HTTP/1.1 302 Found
< Server: nginx/1.18.0
< Date: Tue, 03 Nov 2020 19:30:46 GMT
< Content-Type: text/html; charset=UTF-8
< Content-Length: 0
< Connection: keep-alive
< X-Frame-Options: SAMEORIGIN;
< Content-Security-Policy: script-src 'self' filesystem: 'unsafe-eval' 'unsafe-inline' *.spaggiari.eu https://ajax.googleapis.com/ https://cdnjs.cloudflare.com/ https://cdn.jsdelivr.net/ https://code.jquery.com/ https://d31qbv1cthcecs.cloudfront.net/atrk.js https://fonts.googleapis.com/ https://www.google-analytics.com/ https://www.google.com/recaptcha/ https://www.googletagmanager.com/ https://www.gstatic.com/recaptcha/;frame-ancestors 'self' file: *.spaggiari.eu;
< Set-Cookie: PHPSESSID=pc6u2mc162b30ek2gp9u6phdpt7q85kv; path=/; secure; HttpOnly
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< Pragma: no-cache
< Location: ../../../home/app/default/login.php
< X-ZVersion: c
< Pragma: public
< Cache-Control: public, must-revalidate, proxy-revalidate
< 
* Connection #0 to host web.spaggiari.eu left intact

这是将我发送到登录页面的重定向。所以它告诉我我认为我有一个身份验证问题。现在我不明白我必须做什么才能登录。我有正确的凭据,但我认为我使用的命令有问题。

谢谢大家的回答。

标签: bashshellcurl

解决方案


推荐阅读