Php 如何模拟HTTP请求?
如何模拟HTTP请求。例如,我想模拟将数据插入数据库的请求,以检查程序的安全性和可靠性。有好的工具吗?如果您想从服务器端尝试,cURL绝对是最简单的方法。因为您用PHP标记了这个问题,所以这里有一个模拟POST请求的简单PHP脚本Php 如何模拟HTTP请求?,php,http,jquery,networking,request,Php,Http,Jquery,Networking,Request,如何模拟HTTP请求。例如,我想模拟将数据插入数据库的请求,以检查程序的安全性和可靠性。有好的工具吗?如果您想从服务器端尝试,cURL绝对是最简单的方法。因为您用PHP标记了这个问题,所以这里有一个模拟POST请求的简单PHP脚本 <?php $url = "http://yoursite.com/yourscript.php"; $postdata = array ( "name" => "Joe", "address" => "Some street",
<?php
$url = "http://yoursite.com/yourscript.php";
$postdata = array (
"name" => "Joe",
"address" => "Some street",
"state" => "NY",
);
$req = curl_init($url);
curl_setopt($req, CURLOPT_POST, true);
curl_setopt($req, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($req);
对于*nix操作系统,您可以使用telnet、curl或wget实用程序:
Telnet:
user@host:~$ telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /api.php?param1=10¶m2=20 HTTP/1.1 # here is your request params
Host: localhost # required HTTP header
# double ENTER for sending request
user@host:~$ curl \
--header 'Host: localhost' \
--user-agent 'Mozilla/5.0 (Linux x86_64; rv:10.0.12) Gecko/ Firefox/10.0.12' \
--no-keepalive \
http://localhost/api.php?param1=10¶m2=20
user@host:~$ wget http://localhost/api.php?param1=10¶m2=20
检查操作系统的高级选项
卷曲:
user@host:~$ telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /api.php?param1=10¶m2=20 HTTP/1.1 # here is your request params
Host: localhost # required HTTP header
# double ENTER for sending request
user@host:~$ curl \
--header 'Host: localhost' \
--user-agent 'Mozilla/5.0 (Linux x86_64; rv:10.0.12) Gecko/ Firefox/10.0.12' \
--no-keepalive \
http://localhost/api.php?param1=10¶m2=20
user@host:~$ wget http://localhost/api.php?param1=10¶m2=20
检查操作系统的高级选项。
Wget:
user@host:~$ telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /api.php?param1=10¶m2=20 HTTP/1.1 # here is your request params
Host: localhost # required HTTP header
# double ENTER for sending request
user@host:~$ curl \
--header 'Host: localhost' \
--user-agent 'Mozilla/5.0 (Linux x86_64; rv:10.0.12) Gecko/ Firefox/10.0.12' \
--no-keepalive \
http://localhost/api.php?param1=10¶m2=20
user@host:~$ wget http://localhost/api.php?param1=10¶m2=20
检查操作系统的高级选项。
FYI如果您选择curl,那么您将允许使用*nix shell的强大功能:grep、sed,以及许多其他有用的东西。为了测试您的PHP应用程序,您可以使用如下测试框架:
由一个“http”命令组成,该命令设计用于无痛调试和与http服务器、RESTful API和web服务交互。它可以在所有平台上使用
使用Github API发布有关身份验证问题的评论:
$ http -a USERNAME POST https://api.github.com/repos/jkbrzt/httpie/issues/83/comments body='HTTPie is awesome! :heart:'
我想你可以尝试HTTP请求
您可以填写参数并模拟http请求方法。您是指可以发出http请求的工具吗?一个行业标准是curl:(编辑:啊,你可能是指负载测试-谷歌,例如,服务器负载测试工具
)这不是一个好问题,因此,一些谷歌搜索将为你提供所有你需要的解决方案。我用Acunetix
测试我的web应用程序,你也可以用它修改请求。但如果您只想修改请求,请使用