在OSX中自动化HTTP GET / POST

时间:2012-01-01 09:01:16

标签: macos http osx-lion automator

我需要每小时在路由器上发布我的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中自动化?是否可以为此编写自动脚本?

1 个答案:

答案 0 :(得分:-1)

您可以简单地使用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'

您需要检查网址中的id是否重要。如果没有,上面应该是您所需要的。如果确实如此,那么您可能必须首先请求从其有效负载中获取id