valid json response with Postman but Invalid response with https module - node.js

I am calling this endpoint
https://www.linkedin.com/voyager/api/typeahead/hitsV2?keywords="sousse tunisia"&origin=OTHER&q=type&queryContext=List(geoVersion-%3E3,bingGeoSubTypeFilters-%3EMARKET_AREA%7CCOUNTRY_REGION%7CADMIN_DIVISION_1%7CCITY)&type=GEO
With Postman I get a valid json response. but when I call the same endpoint using https module in node.js code, I get an invalid json response with status 200.
the invalid response is something like this �������Q�[#��=��M�x��Ik�CzEa:H
I am using the accept header like this: _headers['accept']= 'application/vnd.linkedin.normalized+json+2.1'

the other endpoint used a gzip encryption. but this endpoint doesn't.
so I just set the accept-encoding to empty _headers["accept-encoding"] = "". It was confusing that even with the wrong encoding postman showed a correct response.

Related

Not getting the response header location when calling a get request using NodeJS got package

I have a request url which returns a redirection url in response > header > location. But when checking the response.headers after a request using the got package, couldn't see the location parameter in header. Saw something like adding method methodRewriting parameter but doesn't seems to have any effect.

grcp request payload format

I'm trying to log in into a site which requires grcp content-type using requests. I alrady have a HTTP 2 client, but I don't know how body of my post request should look like.
When I'm trying to simply copy request as a curl from chrome network tab, request body looks like this:
%äEMAIL"PASSWORD(0
When I'm trying to request site with same body as I copied from chrome tab, I'mm getting response with this headers:
Grpc-Message: grpc: received message larger than max (218767392 vs. 4194304)
Grpc-Status: 8
I'm sure It's becouse wrong payload format
If anybody knows how can I pass data in request plase help.
If you're trying to send a one-off gRPC request, https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md would be helpful to know as to how to construct a message. Otherwise, using gRPC clients (https://github.com/grpc/grpc) would make more sense.

How to send a url-encoded form data using post request in bot-framework composer

I have an API end-point which takes a query string as url-encoded form data and returns a json.
I have used "Content-Type":"application/x-www-form-urlencoded" as headers.
When I try sending "query=xxx" as body of http post call using composer I get an error in emulator saying "The parent is missing.".
When I try sending {"query":"xxx"} as body, I get an error in emulator saying :
Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.
In which format should I send the data?
You should send it like this:
URL:http://localhost:7071/api/GetStudentGrade
Body(string):studentID=${user.studentID}&coursecode=${user.coursecode}
Content type:application/x-www-form-urlencoded
Detailed image:
I think you have to change the body to an object, Also content type to application/json. Let me know if this resolves your issue.

ContentType is null when making Get requests using ServiceStack JsonServiceClient

In my integration tests, ContentType is null when I make Get requests using ServiceStack's JsonServiceClient. However all the Post requests have a ContentType. Is it excluded on purpose? ie. Do I need a content type for http get requests?
Is there a way I can set the ContentType using this client?
There is no Content-Type for GET Requests since it doesn't have a Request body.
The Content-Type on the Request Header specifies what format the Request Body is in, likewise when on the Response Body specifies what format the Response Body is in.
You may instead be after the Accept HTTP Request Header which tells the server the preferred Content Types it would like the Response in.

Node Express parses request body with JSON incorrectly

I am sending a JSON object from web client, which looks like this:
{"AudioEncoder":{"Settings":{"1":{"audio_bitrate":"16000"}}}}
And in the request I get from req.body.myvalue:
{"AudioEncoder":{"Settings":[null,{"audio_bitrate":"16000"}]}}
In the Network panel of my browser I see correct value though:
myvalue[AudioEncoder][Settings][1][audio_bitrate]:16000
Error is where I am expecting object with key {1:... but get [null:....
Any ideas why would this happen?
I suspect your browser isn't actually sending JSON, it's sending application/x-www-form-urlencoded. This is not the correct value if you are trying to have the browser send JSON: myvalue[AudioEncoder][Settings][1][audio_bitrate]:16000. That's not JSON. Check the request headers for Content-Type and look at the raw body of the request to verify this. If you post your browser JS that's sending the AJAX, we can help you fix that. jQuery makes it a little tricky to specify the options correctly to get it to really send JSON.

Resources