Comments (5)
Have you looked at what the headers coming back from the POST look like? I'm encountering what I think is a similar problem doing a GET to a REST service implemented using Express middleware to return a JSON response. I see that using Express, returning a response with something like
resp.status(200).json({"port":port})
results in a Content-Type header value of "application/json; charset=utf-8"; however, looking at the node-rest-client code, the ConnectionManager is defining known json types as
"jsonctype":["application/json","application/json;charset=utf-8"]
Note the lack of a space between the semi-colon and charset. It appears that it checking for an exact match, so not recognizing that the content is json.
If I change that line to include a type w/ a space:
"jsonctype":["application/json","application/json;charset=utf-8", "application/json; charset=utf-8"]
Then it does recognize the content as json and parse it.
If I'm reading the RFC right (http://www.w3.org/Protocols/rfc1341/4_Content-Type.html) I think the space being present is correct.
from node-rest-client.
Hi @quiquee
have you check the type of data parameter in callback function?? is it a javascript object or just a String? maybe the server response content-type is not declared in the client (because it isn't between the 2 default content-types for JSON responses - @sriddell the ones you mention on your post- or because you have not customize it in client declaration with the parameter "mimetypes") and you are receiving a raw response as String instead a parsed response as a js Object.
@sriddell it's not necessary to modify any source code line to use a different response content-types (please do not mistake REQUEST content-type declared in "headers" parameter in method args with RESPONSE content-type that can be customize with parameter "mimetype" in client instantiation).
Please refer both to issue #39 and in https://github.com/aacerox/node-rest-client#options-parameters)
Thanks.
from node-rest-client.
I have looked at all the other related issues, but still haven't found anyone confirming they have worked this out successfully.
I have followed your recommendations, @aacerox , but I'm not able to set the mimetypes options properly.
At line #18 self.options.mimetypes
seems to be populated correctly, but self.mimetypes
isn't. So, later on in the mergeMimeTypes
function the mimetypes
parameter remains undefined.
Any clue what goes wrong here?
This is a big set back for us, as one of our API frameworks just changed the way they render the Content-Type header, by adding the "; charset=UTF-8" part.
from node-rest-client.
Hi @runarb
I've tried changing content-type in client options and works for me. Here's how I set content-type:
var options={
mimetypes:{json:["test1","test2"]}
};
client = new Client(options);
// just for debug purpose
var req = client.get("http://www.google.com", function(data, response){
// parsed response body as js object
console.log(data);
// raw response
console.log(response);
});
and here's the app debug log with the custom content-types (test1 and test2):
12:43:9 [NRC CLIENT] -> ConnectManager { xmlctype: [ 'application/xml', 'application/xml;charset=utf-8' ],
jsonctype: [ 'test1', 'test2' ],
isXML: [Function],
isJSON: [Function],
isValidData: [Function],
configureRequest: [Function],
configureResponse: [Function],
handleEnd: [Function],
handleResponse: [Function],
proxy: [Function],
normal: [Function],
listeners: [Function],
removeAllListeners: [Function],
removeListener: [Function],
once: [Function],
on: [Function],
addListener: [Function],
emit: [Function],
setMaxListeners: [Function],
_events: { error: [Function] } }
So if you want to set json content-type with "; charset=UTF-8" (with an extra space) you must initialize client as follows:
var options={
mimetypes:{json:["application/json; charset=UTF-8"]}
};
client = new Client(options);
hope it helps.
from node-rest-client.
I'm using [email protected] (iis express server) and had the same problem
Tried changing the mimetypes options but was ignored.
Only solution was to edit node-rest-client.js and add the space value to the jsonctype.
from node-rest-client.
Related Issues (20)
- Vulernability in debug-2.2.0
- promise from http calls HOT 2
- TLS 1.2 Support HOT 1
- Support for retry HOT 1
- Cannot get examples to work HOT 2
- Handle JSON Hijacking prevention HOT 1
- xmlSerializer is not defined
- NPM Vulnerability HOT 2
- Problem behind a Proxy with Tunnel HOT 4
- Can I send a binary file with this?
- "node_modules\node-rest-client\lib\nrc-serializer-manager.js:122" HOT 1
- Result is not defined in nrc-parser-manager HOT 1
- Use a loop? HOT 1
- HTTPS: unable to verify the first certificate error HOT 2
- https encryption
- Content-Type header is case sensitive
- Cannot send multipart/form-data
- The git repository has been abandoned
- "Error: socket hang up" when using node-rest-client if follow-redirects Ver > 1.13.3 HOT 1
- Replace xml2js due to CVE-2023-0842
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-rest-client.