Is there a way to make an HTTP request using the Chrome Developer tools without using a plugin like POSTER?
I've built javascript-snippet (which you can add as browser-bookmark) and then activate on any site to monitor & modify the requests. :
For further instructions, review the github page.
if you use jquery on you website, you can use something like this your console
$.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>
If you want to do a POST from the same domain, you can always insert a form into the DOM using Developer tools and submit that:
To GET requests with headers, use this format.
fetch('http://example.com', {
method: 'GET',
headers: new Headers({
'Content-Type': 'application/json',
'someheader': 'headervalue'
})
})
.then(res => res.json())
.then(console.log)
Since the Fetch API is supported by Chrome (and most other browsers), it is now quite easy to make HTTP requests from the devtools console.
To GET a JSON file for instance:
fetch('https://jsonplaceholder.typicode.com/posts/1')
.then(res => res.json())
.then(console.log)
Or to POST a new resource:
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)
Chrome Devtools actually also support new async/await syntax (even though await normally only can be used within an async function):
const response = await fetch('https://jsonplaceholder.typicode.com/posts/1')
console.log(await response.json())
Notice that your requests will be subject to the same-origin policy, just like any other HTTP-request in the browser, so either avoid cross-origin requests, or make sure the server sets CORS-headers that allow your request.
Using a plugin (old answer)
As an addition to previously posted suggestions I've found the Postman plugin for Chrome to work very well. It allow you to set headers and URL parameters, use HTTP authentication, save request you execute frequently and so on.
I had the best luck combining two of the answers above. Navigate to the site in Chrome, then find the request on the Network tab of DevTools. Right click the request and Copy, but Copy as fetch instead of cURL. You can paste the fetch code directly into the DevTools console and edit it, instead of using the command line.