Created
December 18, 2019 12:51
-
-
Save simonespa/9b73d61784856489a51603a95be45624 to your computer and use it in GitHub Desktop.
User-Agent override test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
| <script src="https://unpkg.com/axios/dist/axios.min.js"></script> | |
| <title>User Agent Override</title> | |
| </head> | |
| <body> | |
| <script> | |
| axios({ | |
| method: 'GET', | |
| url: 'http://127.0.0.1:8080/test', | |
| headers: { | |
| 'User-Agent': 'CustomUserAgent/1.0' | |
| } | |
| }).then((response) => { | |
| const { data } = response; | |
| console.log(data); | |
| }).catch((error) => { | |
| console.log(error.message); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const axios = require('axios'); | |
| axios({ | |
| method: 'GET', | |
| url: 'http://127.0.0.1:8080/test', | |
| headers: { | |
| 'User-Agent': 'CustomUserAgent/1.0' | |
| } | |
| }).then((response) => { | |
| const { data } = response; | |
| console.log(data); | |
| }).catch((error) => { | |
| console.log(error.message); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const express = require('express') | |
| const cors = require('cors'); | |
| const app = express() | |
| const port = 8080 | |
| const corsOptions = { | |
| optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204 | |
| } | |
| app.use(cors(corsOptions)); | |
| app.get('/test', (request, response) => { | |
| const { headers } = request; | |
| response.json({ headers }); | |
| }); | |
| app.listen(port, () => console.log(`Example app listening on port ${port}!`)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment