如何通过操作当前页面将POST请求发送到某个网页?

时间:2012-03-29 22:08:16

标签: php security http post header

我想设置标题,如post变量名称和值以及send和expect响应。 这也是一个安全问题,假设我想发送一个表单变量,其中action =“delete”和userid = 100,让我们说,我找到了一个接受ajax请求的文件。

3 个答案:

答案 0 :(得分:1)

curl 是您的朋友! :)

假设您已注意到表单发布到example.org/process.php的端点。您可以使用curl从命令行轻松定制自己的自定义请求。

$ curl -X POST --data "action=delete&userid=100" example.org/process.php

--data-D标记允许您像HTML表单一样传递任意POST数据。您还可以轻松设置HTTP请求标头:

$ curl --header "User-Agent: Mosaic" example.org/process.php

您可以准确地看到-v(详细)标志发生了什么。对于上面的第一个示例,输出为:

* About to connect() to example.org port 80 (#0)
*   Trying 192.0.43.10... connected
* Connected to example.org (192.0.43.10) port 80 (#0)
> POST /process.php HTTP/1.1
> User-Agent: curl/7.21.6 (x86_64-apple-darwin10.5.0) libcurl/7.21.6 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.22
> Host: example.org
> Accept: */*
> Content-Length: 24
> Content-Type: application/x-www-form-urlencoded
> 
* HTTP 1.0, assume close after body
< HTTP/1.0 302 Found
< Location: http://www.iana.org/domains/example/
< Server: BigIP
* HTTP/1.0 connection set to keep alive!
< Connection: Keep-Alive
< Content-Length: 0
< 
* Connection #0 to host example.org left intact
* Closing connection #0

如果您使用的是包含Mac OS X的* NIX操作系统,您可能已经拥有curl,只需打开一个shell即可。如果你完全使用Ruby,我强烈推荐curb,这是一种针对该语言的绑定。大多数PHP安装都支持curl,虽然界面非常糟糕。文档已在php.net结束。

答案 1 :(得分:0)

您可以使用CURL library。查看more info

您可以发送数据POST / GET方法,上传文件,SSL支持,cookie支持,ftp支持等等

答案 2 :(得分:0)

您可能还想看看史努比(http://sourceforge.net/projects/snoopy/

它是一个PHP类,旨在充当Web浏览器,具有许多有用的功能,如模拟HTTP请求,操作表单数据等。