在 OSX 中自动化 HTTP GET/POST

发布于 2024-12-23 10:22:18 字数 1200 浏览 6 评论 0原文

我需要每小时在路由器上释放我的 IP 地址。路由器页面需要简单的身份验证和单击按钮来完成该过程。这些是 HTTP 调用:

单击“验证

GET /RST_st_dhcp.htm HTTP/1.1
Host: 10.10.1.1
Authorization: Basic YWRtaW46cGFzc3dvcmQ=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

发布”按钮

POST /st_dhcp.cgi?id=1044071018 HTTP/1.1
Host: 10.10.1.1
Content-Length: 31
Cache-Control: max-age=0
Authorization: Basic YWRtaW46cGFzc3dvcmQ=
Origin: http://10.10.1.1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Referer: http://10.10.1.1/RST_st_dhcp.htm
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

connect=Release&refreshScrn=yes

如何在 OSX 中自动执行此操作?是否可以为此编写自动化脚本?

I need to release my IP address at the router on an hourly basis. The router page needs simple authentication and a button click to do the process. These are the HTTP calls:

Authenticate

GET /RST_st_dhcp.htm HTTP/1.1
Host: 10.10.1.1
Authorization: Basic YWRtaW46cGFzc3dvcmQ=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

Release button click

POST /st_dhcp.cgi?id=1044071018 HTTP/1.1
Host: 10.10.1.1
Content-Length: 31
Cache-Control: max-age=0
Authorization: Basic YWRtaW46cGFzc3dvcmQ=
Origin: http://10.10.1.1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Referer: http://10.10.1.1/RST_st_dhcp.htm
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

connect=Release&refreshScrn=yes

How can this be automated in OSX? Is it possible to write automator scripts for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光沙漏 2024-12-30 10:22:19

您可以简单地使用curl来发出该请求 - 例如

curl -e http://10.10.1.1/RST_st_dhcp.htm \
  -d 'connect=Release&refreshScrn=yes' -u user:password \
  'http://10.10.1.1/st_dhcp.cgi?id=1044071018'

您需要检查URL中的id是否重要。如果没有,以上应该就是您所需要的。如果是这样,那么您可能必须发出第一个请求才能从其负载中获取id

You can simply use curl to make that request - something like

curl -e http://10.10.1.1/RST_st_dhcp.htm \
  -d 'connect=Release&refreshScrn=yes' -u user:password \
  'http://10.10.1.1/st_dhcp.cgi?id=1044071018'

You'll need to check whether the id in the URL matters. If not, the above should be all you need. If it does then you may have to make the first request to get the id from its payload.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文