Express JS changing line break type to CRLF - express

I am trying to make a HTTP request from a Flutter App to a Express-JS Server running on an Ubuntu machine. A newer version of Flutter(v1.22.5) throws following error when making the Request:
E/flutter (29477): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: Invalid response, unexpected 10 in reason phrase
The code for making the request looks like this:
final response = await http.get(
'http://XX.XX.XXX.XXX/employees', //Hiding IP address for privacy purposes
headers: {
"Content-Type": "application/json",
"Authorization": api_key,
},
);
print(response.statusCode);
I can confirm by using HTTP-Tester Insomnia that the queried URL does indeed return information.
The issue seems to be known and can be viewed here
According to the Github-Thread, the issue is due to wrong line break format in the headers.
How can I tell Express JS to use CRLF?

For anyone stumbling across this question, I fixed it by reconfiguring my API-Server. Closer inspection of this problem lead to the conclusion that neither the App nor the API was bad, due to the fact no API-Request did actually reach my API-Code. I figured it out by simply looking at the logs. In my case, it was NginX not working properly as a reverse-proxy. I followed this tutorial to properly set it put.

Related

Nuxt 3 $fetch method doesn't work with golang servers?

UPD: you can check this yourself: https://github.com/Rusinas/nuxt-fetch-bug
I know I know this sounds stupid as hell and server language has nothing to do with such problems, but hear me out.
I am trying to load data from my local server using $fetch() (or useFetch, no difference), but I get this error:
FetchError: fetch failed ()
No any other details provided. Server is running using Golang/Fiber. When I am trying to load the same endpoint via Postman, everything is OK:
But when I try to load the SAME endpoint in my nuxt 3 application:
I get this:
But my golang server logging this as success:
The more weird thing about all this is that if I run my nodejs version of the exact same server (or any other random API), I don't get any error.
I am pretty sure that my server working 100% correct, but maybe I lost some header or something, which express put automatically? Here is my response headers:
I also checked nodejs response headers:
Doesn't seem like problem is there.
I have no idea what is happening and I don't know other methods to retrieve async data on server side in nuxt js. I have installed axios, but it throws random errors and works on client side for some reason, which makes using nuxt meaningless. However, axios can call this endpoint and returns my data, but only in browser (despite I call it in setup function without any hooks). I am thinking to switch career now
The problem was that fetch() didn't reconize localhost:9000 for some
reason, but when I changed BASE_URL to 127.0.0.1:9000 it started to
work
I had the same error: FetchError: fetch failed ()
Changing localhost in the url to 127.0.0.1 worked for me.
Writing as a separate answer because some might not find it in the comments.
First I think you are using $fetch in a wrong way, as I've seen Nuxt uses fetch for example:
const data = await fetch(endpoint, {
method: "GET",
mode: "cors"
})
.then(resp => resp.json())
And for the server, just enable CORS header on the response, like this:
// you can replace the asterisk with the clients you want.
c.Append("Access-Control-Allow-Origin", "*")
hope I helped :)

Recieving 404 error when running get request to Amadeus low-fare-search API

Hi I am very new to Angular and programming in general and I have been trying to query the Amadeus low-fare-search with Angular HTTPClient and failing, I have been looking around for answers, but havent found anything specific to this, I have found some answers related to the specific problem of "unable to identify proxy".
And according to some the reason for this is that the URL is incorrect.
But this is the URL on Amadeus page
Resource URL
This is the code i am trying to run :
search(){
return this.http.get('http://api.sandbox.amadeus.com/v1.2/flights/low-fare-search?origin=IST&destination=BOS&departure_date=2018-10-15&return_date=2018-10-21&number_of_results=3&apikey=my API key')
.subscribe((data) =>{
console.log(data)},
(err) => {console.log(err)});
Here is the error message
errorcode: "messaging.adaptors.http.flow.ApplicationNotFound"
faultstring:"Unable to identify proxy for host: default and url:
/v1.2/flights/low-fare-search"
Can someone explain to me in simple terms what could be causing this error?
In your example, you are using http instead of https
I tested your example and it works for me:
https://api.sandbox.amadeus.com/v1.2/flights/low-fare-search?origin=IST&destination=BOS&departure_date=2018-10-15&return_date=2018-10-21&number_of_results=3&apikey={your_api_key}

github API unsupported media type 415

I was using github API in Meteor but could not solved this issue:
This code tries to get the total number of traffic for a certain repo.
HTTP.call( 'GET', 'https://api.github.com/repos/hackmdio/hackmd/traffic/views',
{
headers:
{
'Content-Type':'application/json',
"Accept":"application/vnd.github.v3+json",
"User-Agent": "whales"
},
},
function( error, response ) {
if ( error ) {
console.log('---------------------------error occurred-----------------------------------')
console.log('---------------------------error occurred-----------------------------------')
console.log( error );
} else {
console.log('--------------------------data got it!!-------------------------------------')
console.log('--------------------------data got it!!-------------------------------------')
console.log(response);
}
});
Error:
{
"message": "If you would like to help us test the Repo Traffic API during its preview period, you must specify a custom media type in the 'Accept' header. Please see the docs for full details.",
"documentation_url": "https://developer.github.com/v3"
}
I searched for similar issues and added "Content-Type" and "Accept" but it's still not working.
I then tried doing this in Postman and also in terminal with the same headers but this error kept happening.
Thanks a lot.
You will need to add an Accept: application/vnd.github.spiderman-preview header to your request in order to access the Repo Traffic API whilst it is in preview form. From the API docs:
APIs for repository traffic are currently available for developers to preview. During the preview period, the APIs may change without advance notice. Please see the blog post for full details.
To access the API you must provide a custom media type in the Accept header:
application/vnd.github.spiderman-preview
The Commit Search API is currently available for developers to preview. During the preview period, the APIs may change without advance notice.
To access the API you must provide a custom media type in the Accept header:
Accept: application/vnd.github.cloak-preview
☝️This header is required.
check docs
To anyone who ends up on this page after googling why GitLab API has started throwing 415 when sending POST requests:
Make sure you pass the Content-Type: application/x-www-form-urlencoded header if you're sending stuff via post-data fields. Their docs never mention this b/c apparently many clients (like curl) do this automatically.

How to bypass the Sails body parser for multi-part form uploads

I am facing a problem on Sails.js (0.9.16) with POST requests sent from a JAVA client.
On the client side I built a POST request (with enctype : multipart/form-data) sending a text file.
On the server side, I created a controller with a method (action) getRequest which looks like :
getRequest: function (req, res, next) {
//var busboy = require('connect-busboy');
console.log('req: ', req);
return res.send(200);
}
But I have the following error on my sails.js console:
Error: 'Unable to parse HTTP body :: { [error: Expected CR Received 10] status: 400 }
So I saw on the Web that Express/Connect included with Sails.js was not appropriate to handle multipart data, has anybody already faced my problem and succeed to use an other middleware like busboy or formidable to handle these kind of request?
Thanks in advance.
Best
Loïc
I've been trying to solve this problem as well. Looks like skipper from the sails team is the way to go. https://github.com/balderdashy/skipper
The docs appear to be decent w/ examples for sails 0.10.0 & 0.9.x.
See this thread on GitHub https://github.com/balderdashy/sails/issues/1521 for more info and background.
Hope this helps. FYI - The google group for sails is active.
Graham

IIS 7 Serves GET request correctly to browser but throws timeout exception for API request

I am running a very simple Web application (Asp.Net MVC3) on Win 7 IIS.
I have a very simple HTTP GET API which returns hello world.
Calling:
http://localhost/helloworld
Returns:
Hello World!
This works perfectly over a browser.
But when I write an app which tries to pull this URL using a webclient, I get the following error:
{"Unable to read data from the transport connection: The connection was closed."}
My Code is as follows
WebClient web = new WebClient();
var response = web.DownloadString("http://localhost/helloworld");
My IIS Settings are as follows
What should I be looking at? I have been at this for hours and I have run out of options to try! Any help will be really appreciated!
Thanks.
I suspect it's because WebClient does not send some of the HTTP headers:
A WebClient instance does not send optional HTTP headers by default. If your request requires an optional header, you must add the header to the Headers collection. For example, to retain queries in the response, you must add a user-agent header. Also, servers may return 500 (Internal Server Error) if the user agent header is missing. http://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.80).aspx
Try using HttpWebRequest instead. http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx
I finally figured out what the issue was and instead of it being an IIS specific issue - which I was leaning towards, it turned out to be an issue with the code that I wrote.
Adding details here incase someone else runs into a similar problem.
I had the following method in my code which I was using to send the response of the request as a JSON object.
private void sendJsonResult(string result) {
Response.StatusCode = 200;
Response.Headers.Add("Content-Type", "application/json; charset=utf-8");
Response.Flush();
Response.Write(result);
Response.End();
Response.Close(); // <-- This is the problem statement
}
On digging around a bit, I found out that we should not be doing a Response.Close().
A better explanation of this is here.
Once I removed that line, it started working perfectly - both in my consuming app as well as the web browser, etc.
If you will read the link above, you will clearly understand why we should not be using a Response.Close() - so I will not go into that description. Learnt a new thing today.