如何模拟HTTP请求。例如,我想模拟将数据插入到数据库的请求,以检查程序的安全性和可靠性。有一些好的工具吗?如何模拟HTTP请求?
2
A
回答
1
如果你想从服务器端尝试cURL绝对是最简单的方法。由于您用PHP标记了这个问题,因此这里是一个模拟POST请求的简单PHP脚本。
<?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);
如果您想尝试浏览器的请求,Chrome和Firefox都有很好的扩展。例如(对于铬)POSTMAN或Advanced REST client。
4
对于Unix操作系统,你可以使用的telnet,卷曲或wget的 UTILITES:
远程登录:
[email protected]:~$ 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
检查您的操作系统的高级选项的telnet man-page。
卷曲:
[email protected]:~$ 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
检查您的操作系统的高级选项的curl man-page。
的Wget:
[email protected]:~$ wget http://localhost/api.php?param1=10¶m2=20
检查您的操作系统的高级选项的wget man-page。
FYI如果选择卷曲,那么你就允许使用的* nix的外壳功率:grep的,sed的,output redirection和很多其他有用的东西。
1
为了测试你的PHP应用程序,你可以使用一个测试框架,如:SimpleTest
<?php
require_once('simpletest/browser.php');
$browser = &new SimpleBrowser();
$browser->get('http://php.net/');
$browser->click('reporting bugs');
$browser->click('statistics');
$page = $browser->click('PHP 5 bugs only');
preg_match('/status=Open.*?by=Any.*?(\d+)<\/a>/', $page, $matches);
print $matches[1];
?>
0
HTTPie由单一的“HTTP”命令专为无痛调试和使用HTTP服务器的交互,基于REST API和Web服务。它可以在所有平台上使用。
$ http www.google.com search=='HTTPie logo' tbm==isch
GET /?search=HTTPie+logo&tbm=isch HTTP/1.1
相关问题
- 1. 如何使用Python请求模块来模拟HTTP post请求?
- 2. 守夜模拟HTTP请求
- 3. HTTP和Ajax请求模拟
- 4. 模拟HTTP POST请求
- 5. 如何模拟AJAX请求?
- 6. 如何模拟POST请求?
- 7. 在Python中模拟HTTP发布请求
- 8. 什么是“IIS模拟HTTP请求”?
- 9. 使用jpcap模拟HTTP请求
- 10. node.js:模拟http请求和响应
- 11. 在Angular 4中模拟http请求
- 12. Django - 模拟http发布请求
- 13. 在grails中模拟外部http请求
- 14. 使用CURL工具模拟HTTP请求
- 15. 模拟一个HTTP请求与卷曲
- 16. 模拟单元测试的HTTP请求
- 17. 使用Nock和请求模拟HTTP请求错误
- 18. 如何模拟rest-easy的异步HTTP请求?
- 19. 如何发送http请求到android模拟器
- 20. 如何模拟与Apache公共的ServletFileUpload兼容的HTTP请求?
- 21. 如何模拟http:请求配置有oauth2
- 22. 如何模拟代码中的Web浏览器http请求?
- 23. 模拟POST请求
- 24. 如何模拟Google API AndroidPublisher请求
- 25. 如何模拟请求浏览器C#?
- 26. 如何在JUNIT中模拟请求(spring)
- 27. 如何模拟WebTest下的HTTPS请求?
- 28. 如何模拟查看请求。
- 29. http请求的HTTP请求
- 30. 如何在C#中模拟此请求请求#
你的意思是一个工具,可以*使* HTTP请求?一个行业标准是curl:http://curl.haxx.se/(编辑:啊,你可能是指负载测试 - 谷歌,例如,“服务器负载测试工具”)这不是一个好的问题,一些谷歌搜索会为您提供所有您需要的解决方案。 –
我用'Acunetix'测试我的web应用程序,你也可以用它来修改请求。但如果您只想修改请求,请使用[篡改数据](https://addons.mozilla.org/en-US/firefox/addon/tamper-data) – undone