Is there a way to make an HTTP request using the Chrome Developer tools without using a plugin like POSTER?
-
1Are you hoping to make requests cross-domain, or on the same domain in which you opened the developer tools?Lukas– Lukas2013-01-09 23:31:00 +00:00Commented Jan 9, 2013 at 23:31
-
6For all the people wanting this feature -- star this Chromium issue: code.google.com/p/chromium/issues/…Ivan Zuzak– Ivan Zuzak2013-01-10 20:06:20 +00:00Commented Jan 10, 2013 at 20:06
-
1All were useful answers, just wanted to add a tool I find pretty useful Advanced Rest Client. Using this can help one save a lot of time in the long run if one is going to make multiple API requests.Sagar Ranglani– Sagar Ranglani2016-10-18 13:01:09 +00:00Commented Oct 18, 2016 at 13:01
-
11Firefox is a better option for this. just right-click on the request and resend or edit and resend.imbr– imbr2017-08-21 19:10:07 +00:00Commented Aug 21, 2017 at 19:10
-
@eusoubrasileiro: Thanks. The Edit&Resend button in the network tab in Firefox to resend a request is really nice feature. Hope someone raises a request to add it in chrome as wellfirstpostcommenter– firstpostcommenter2019-11-10 10:31:30 +00:00Commented Nov 10, 2019 at 10:31
15 Answers
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.
8 Comments
fetch("/echo/json/", { method: "POST", body: data })mode request option you can use: fetch("/echo/json/", { method: 'POST', mode: 'no-cors' }. Note that mode: "no-cors" only allows a limited set of headers in the request. More info about using fetch and no-corsIf you want to edit and reissue a request that you have captured in Chrome Developer Tools' Network tab:
- Right-click the
Nameof the request - Select
Copy > Copy as cURL - Paste to the command line (command includes cookies and headers)
- Edit request as needed and run
7 Comments
I know, old post ... but it might be helpful to leave this here.
Modern browsers are now supporting the Fetch API.
You can use it like this:
fetch("<url>")
.then(data => data.json()) // could be .text() or .blob() depending on the data you are expecting
.then(console.log); // print your data
ps: It will make all CORS checks, since it's an improved XmlHttpRequest.
Comments
Expanding on @dhfsk answer
Here's my workflow
3 Comments
If your web page has jquery in your page, then you can do it writing on chrome developers console:
$.get(
"somepage.php",
{paramOne : 1, paramX : 'abc'},
function(data) {
alert('page content: ' + data);
}
);
Its jquery way of doing it!
5 Comments
GET requests, if you want to do other types of requests, you may want to make use of $.ajaxvar script = document.createElement("script"); script.src = "http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.js"; document.body.appendChild(script);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.
1 Comment
Using modern async/await javascript sintax you could do it as follow below.
const options = {method: 'GET', Content-Type: 'application/json'};
let res = await fetch('https://yourdomain.com/somedata.json', options);
let json = await res.json();
It will make all CORS checks (Cross-Origin Resource Sharing). Case the web server already allow CORS from all domains you are ready to go. Case you need enable CORS on the web server follow below 2 cases: one with nginx and another with node express.
Enable CORS with NGINX
Enable CORS from all websites If you want to enable CORS for all websites, that is, accept cross domain requests from all websites, add the following
add_header Access-Control-Allow-Origin *;
Enable CORS from one domain
add_header Access-Control-Allow-Origin "stackoverflow.com";
Enable CORS with Express
With node it's just install cors with yarn add cors, and then use it
var express = require('express')
var cors = require('cors')
var app = express()
app.use(cors())
app.get('/products/:id', function (req, res, next) {
res.json({msg: 'This is CORS-enabled for all origins!'})
})
app.listen(80, function () {
console.log('CORS-enabled web server listening on port 80')
})
Comments
You can edit/resend a request in Firefox's Inspector without using any 3rd parties like so:
- Press F12 to open the inspector in Firefox ▶ go to the Network tab
- Find your API request and click on it so the 'Headers' section will appear to the right (you can filter in the bar on top)
- The 'Header' tab comes with a Resend button, here you can either Resend or Edit and Resend
Comments
$.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>
1 Comment
Yes, there is a way without any 3rd party extension.
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.



