如何通过浏览器地址栏中的URL传递POST参数

我们可以从网页中找出POST请求所使用的参数,例如 如何查看单击HTML按钮时发出的POST请求的地址?

方法是否可以POST在地址栏中或从调试器控制台输入带有参数的 url?

对于get请求,在地址和参数之间插入一个?,例如

https://www.w3schools.com/action_page.php?fname=Albert&lname=Einstein.

(模拟帖子表单调用相同的脚本。)



繁星淼淼
浏览 173回答 3
3回答

蓝山帝景

当然, POST 方法可以在地址中传递参数。设置一个表单以使用操作进行 POST /foo?bar=bat,服务器将获取POST表单参数和查询字符串参数。动态创建操作以便操作中的查询字符串包含表单参数是很简单的。例如 - 这里,当提交表单时,POST 数据会在通过 ajax 发布表单之前附加到查询字符串中。这样您就可以在 URL 和正文数据中获取 post 参数。html<!DOCTYPE html><html>&nbsp; <body>&nbsp; &nbsp; <form action="/something">&nbsp; &nbsp; &nbsp; <label for="fname">First name:</label><br>&nbsp; &nbsp; &nbsp; <input type="text" id="fname" name="fname" value="John"><br>&nbsp; &nbsp; &nbsp; <label for="lname">Last name:</label><br>&nbsp; &nbsp; &nbsp; <input type="text" id="lname" name="lname" value="Doe"><br><br>&nbsp; &nbsp; &nbsp; <input type="submit" value="Submit">&nbsp; &nbsp; </form>&nbsp; </body></html>js$("form").submit(function(e) {&nbsp; e.preventDefault();&nbsp; const form = $(e.currentTarget);&nbsp; const data = form.serialize();&nbsp; $.ajax({&nbsp; &nbsp; type: "POST",&nbsp; &nbsp; url: `${form.attr("action")}?${data}`,&nbsp; &nbsp; data: data,&nbsp; &nbsp; success: function() {&nbsp; &nbsp; &nbsp; console.log("woot!");&nbsp; &nbsp; }&nbsp; });});也就是说,这可能根本不是一个好主意。

天涯尽头无女友

这是不可能的。POST 参数只能通过请求正文传递。您可以使用某种 API 客户端工具,例如Postman、Paw或仅使用普通的curl。

哆啦的时光机

可以在调试器控制台中运行以下命令。它操纵一个输入字段。form=document.getElementsByName("form0")[0]; form.isource.value="Gaia"; form.target="_blank"; form.submit()该 url 已经继承自form.action.
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5