翻譯|使用教程|編輯:董玉霞|2022-03-30 11:00:39.437|閱讀 348 次
概述:本節介紹 HTTP 請求格式。要在 phpStorm 碼編輯器中編寫 HTTP 請求,請使用以下通用語法。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
本節介紹 HTTP 請求格式。要在 phpStorm 碼編輯器中編寫 HTTP 請求,請使用以下通用語法:
Method Request-URI HTTP-Version Header-field: Header-value Request-Body
// A basic request GET //example.com/a/
// A basic request //example.com/a/
// A basic request //example.com/a/ ###
// A basic request //example.com/a/ ### // A second request using the GET method //example.com:8080/api/html/get?id=123&value=content
// Using line breaks with indent GET //example.com:8080 /api /html /get ?id=123 &value=content
// Basic authentication GET //example.com Authorization: Basic username password ### // Digest authentication GET //example.com Authorization: Digest username password
與其他 HTTP 請求的元素類似,提供的username和password可以通過環境變量參數化。
在請求中,在請求正文前添加一個空行并執行以下操作之一:
// The request body is provided in place POST //example.com:8080/api/html/post HTTP/1.1 Content-Type: application/json Cookie: key=first-value { "key" : "value", "list": [1, 2, 3] }
如果您將Content-Type標頭字段值設置為 PhpStorm 支持的語言之一,則相應的語言片段將自動注入到 HTTP 請求消息正文中。如果沒有指定Content-Type ,您可以手動注入語言片段。
// The request body is read from a file POST //example.com:8080/api/html/post Content-Type: application/json < ./input.json
POST //example.com/api/upload HTTP/1.1 Content-Type: multipart/form-data; boundary=boundary --boundary Content-Disposition: form-data; name="first"; filename="input.txt" // The 'input.txt' file will be uploaded < ./input.txt --boundary Content-Disposition: form-data; name="second"; filename="input-second.txt" // A temporary 'input-second.txt' file with the 'Text' content will be created and uploaded Text --boundary Content-Disposition: form-data; name="third"; // The 'input.txt' file contents will be sent as plain text. < ./input.txt --boundary--
根據您訪問的 Web 服務,您可能希望 HTTP 請求遵循重定向或不遵循重定向。跟隨重定向時,返回重定向的頁面響應;否則,返回實際的重定向響應頭(例如301或302)。
// @no-redirect example.com/status/301
如有必要,您可以阻止將請求保存到requests history。如果請求包含一些敏感數據并且您不想記錄它,這會很有幫助。
// @no-log GET example.com/api
如有必要,您可以阻止將接收到的 cookie 保存到 cookies jar中。這樣,您將避免手動從http-client.cookies文件中刪除不需要的 cookie。
// @no-cookie-jar GET example.com/api
以上就是HTTP請求語法的相關內容,下載phpstorm最新版本來確保自己功能達到最新。
phpstorm是一個輕量級且便捷的PHP IDE,其旨在提高用戶效率,可深刻理解用戶的編碼,提供智能代碼補全,快速導航以及即時錯誤檢查。可隨時幫助用戶對其編碼進行調整,運行單元測試或者提供可視化debug功能。
JetBrain技術交流群現已開通,QQ搜索群號“786598704”,歡迎進群討論。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn