是否有一种方法可以在不使用POSTER等插件的情况下,使用Chrome开发者工具进行HTTP请求?
是否有一种方法可以在不使用POSTER等插件的情况下,使用Chrome开发者工具进行HTTP请求?
fetch('https://jsonplaceholder.typicode.com/posts/1')
.then(res => res.json())
.then(console.log)
使用POST方法:
fetch('https://jsonplaceholder.typicode.com/posts', {
method: 'POST',
body: JSON.stringify({
title: 'foo',
body: 'bar',
userId: 1
}),
headers: {
'Content-type': 'application/json; charset=UTF-8'
}
})
.then(res => res.json())
.then(console.log)
const response = await fetch('https://jsonplaceholder.typicode.com/posts/1')
console.log(await response.json())
fetch("/echo/json/", { method: "POST", body: data })
- Christofer Eliassonmode
请求选项:fetch("/echo/json/", { method: 'POST', mode: 'no-cors' }
。请注意,mode: "no-cors" 只允许请求中的有限一组标头。有关使用 fetch 和 no-cors 的更多信息。 - Christofer Eliasson$.get(
"somepage.php",
{paramOne : 1, paramX : 'abc'},
function(data) {
alert('page content: ' + data);
}
);
这是使用jQuery的方式来完成它!
$.ajax
。 - aksu我发现将上面两个答案结合起来效果最好。在Chrome中导航到网站,然后在DevTools的Network选项卡中找到请求。右键点击该请求并选择Copy as fetch而不是cURL。您可以直接将fetch代码粘贴到DevTools控制台中并进行编辑,而无需使用命令行。
要使用头信息进行 GET 请求,请使用以下格式。
fetch('http://example.com', {
method: 'GET',
headers: new Headers({
'Content-Type': 'application/json',
'someheader': 'headervalue'
})
})
.then(res => res.json())
.then(console.log)
如果您在网站上使用jQuery,您可以在控制台中使用以下内容:
$.post(
'dom/data-home.php',
{
type : "home", id : "0"
},function(data){
console.log(data)
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
简单来说,如果你希望请求使用与你当前正在查看的页面相同的浏览上下文,则只需在Chrome控制台中执行以下操作:
window.location="https://www.example.com";