-
-
Notifications
You must be signed in to change notification settings - Fork 11.5k
Closed
Description
Describe the bug
I want to get a response as string even if that comes as application/json. Parsing the response to an object is not required and not desired as the only thing I have to do with it is rewrite some urls and I am not sure of the content type the server will use.
To Reproduce
Server:
const http = require("http");
const server = http.createServer((req, res) => {
res.writeHead(200, {"Content-Type": "application/json"});
res.end("{\"doNotParse\": 1}");
});
server.listen(1234);Client:
const axios = require("axios");
axios.request({url: "http://localhost:1234/", responseType: "text"})
.then(res => console.log("Type of data is %s", typeof res.data));Outcome:
Type of data is object
Expected behavior
response data should be the string "{\"doNotParse\": 1}", the program would print:
Type of data is string
Environment:
- Axios 0.19.2
- Fedora 31
- Node 12
Additional context/Screenshots
Setting transformResponse: (data) => data appears to do the trick, regardless of responseType.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels