如何模擬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