Why does this work in curl but not in HTTP.get?


#1

So, when I use this URL in a terminal with cURL, I get a 200 response and content response (content node is empty).

$ curl “http://api.crispwireless.com/shorten.v1/text.json?partnerkey=InternalNetwork&text=asdf

{“url”:“http://shortn.me/kpxn",“qr”:"http://shortn.me/qrcodes/kpxne7c01bcf61654c9f2f916284ce32776b.png”}

But when I use server-side Meteor HTTP.get, I get a 200 response with an empty response

var url = “http://api.crispwireless.com/shorten.v1/text.json?partnerkey=InternalNetwork&text=asdf”;

var result = HTTP.get(postUrl);

console.log(“statusCode=” + result.statusCode);
console.log(“result=” + JSON.stringify(result, null, 2));

statusCode=200
result={
“statusCode”: 200,
“content”: “”,
“headers”: {
“date”: “Sun, 22 Mar 2015 19:44:08 GMT”,
“server”: “Apache”,
“x-powered-by”: “PHP/5.3.29”,
“vary”: “Accept-Encoding,User-Agent”,
“content-length”: “0”,
“content-type”: “text/html; charset=UTF-8”,
“set-cookie”: [
“CURRENT_LANGUAGE=en; expires=Mon, 23-Mar-2015 19:44:09 GMT”
],
“node”: “WEB5J”,
“keep-alive”: “timeout=2, max=100”,
“connection”: “Keep-Alive”
},
“data”: null
}

Any ideas on why my HTTP.get call has an empty content even though a simple curl seems OK? Is there a better way in Meteor to get the response from this API?

Thanks,
-Nathan


#2

Try setting a header Accept: json/application on your request.