How do I set request headers using Meteor HTTP? - http

I have a meteor method which uses HTTP.get to make a request to an API. From what I understood from the docs I can provide options with a headers object to set various things like Content-Type. I've tried this with the following code:
var r = HTTP.call("GET", apiUrl, { headers: { "Content-Type": "application/json" } });
console.log(r);
But this doesn't seem to work, the content type is till "text", see output below:
I20160302-13:50:22.706(0)? headers:
I20160302-13:50:22.706(0)? { 'access-control-allow-headers': 'Content-Type, api_key, Authorization',
I20160302-13:50:22.707(0)? 'access-control-allow-methods': 'GET',
I20160302-13:50:22.707(0)? 'access-control-allow-origin': '*',
I20160302-13:50:22.707(0)? 'content-type': 'text/plain; charset=utf-8',
I20160302-13:50:22.707(0)? date: 'Wed, 02 Mar 2016 13:50:20 GMT',
I20160302-13:50:22.707(0)? server: 'nginx/1.6.2',
I20160302-13:50:22.707(0)? 'content-length': '267',
I20160302-13:50:22.707(0)? connection: 'keep-alive' },
I've tried switching this about using "content-type" and "Content-Type". I've also tried using the shortened HTTP.get function

Related

Python calling PUT request : 'PUT' not supported

I am trying to call an API on a 3rd party application (Qlik Catalog).
They provide a Swagger page where I have tested the call, and it provides a curl:
curl
-X PUT "http://xxxxnnnnnn.xxxxxxx.xxxx.xxx:nnnn/qdc/entity/v1/loadDataForEntities/true"
-H "accept: */*"
-H "Content-Type: application/json"
-H "X-XSRF-TOKEN: xnxnxnxn-xxxx-xxxx-xxxx-xxxx"
-d "[{\"entityId\":\"1234\",\"loadType\":\"OVERWRITE\",\"loadTime\":\"123456789012\"}]"
I am implementing this via Python but getting:
Request method 'PUT' not supported
Any ideas what the problem might be ??
Thanks
Code below (with lots of debug printing!):
url_stem = 'http://xxxxnnnnnn.xxxxxxx.xxxx.xxx:nnnn/qdc/entity/v1/loadDataForEntities/true'
payload = [{"entityId":"1234","loadType":"OVERWRITE","loadTime":"123456789012"}]
headers = {'accept': '*/*','Content-type': 'application/json','X-XSRF-TOKEN':'xnxnxnxn-xxxx-xxxx-xxxx-xxxx'}
print('-------------------------')
print('[Sending]..')
print(' url: %s' % (url_stem))
print(' payload: %s' % (payload))
print(' headers: %s' % (session.headers))
print(' cookies: %s' % (session.cookies))
response = session.put(url_stem, json=payload, headers=headers)
print('-------------------------')
print(' Reponse.....')
print(' [Status]:%s' % response)
print(' [response json]: %s' % response.json())
print(' [rsp:Headers]:%s' % response.headers)
print('-------------------------')
And the CMD output:
[Sending]..
url: http://xxxxnnnnnn.xxxxxxx.xxxx.xxx:nnnn/qdc/entity/v1/loadDataForEntities/true
payload: [{'entityId': '1234', 'loadType': 'OVERWRITE', 'loadTime': '123456789012'}]
headers: {
'accept': '*/*',
'Content-type': 'application/json',
'X-XSRF-TOKEN': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx'
}
sess cooks: <RequestsCookieJar[
<Cookie JSESSIONID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx for xxxxnnnnnn.xxxxxxx.xxxx.xxx/qdc>,
<Cookie XSRF-TOKEN=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx for xxxxnnnnnn.xxxxxxx.xxxx.xxx/qdc>
]>
-------------------------
Reponse.....
[Status]:<Response [405]>
[response json]: {
'code': 'DYNAMIC_ERROR',
'fullCode': 'pgui.error.code.DYNAMIC_ERROR',
'message':"pgui.error.code.DYNAMIC_ERROR - Request method 'PUT' not supported",
'localizedMessage': "pgui.error.code.DYNAMIC_ERROR - Request method 'PUT' not supported"
}
[rsp:Headers]:{
'X-Content-Type-Options': 'nosniff',
'X-XSS-Protection': '1;
mode=block',
'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate',
'Pragma': 'no-cache',
'Expires': '0',
'Content-Security-Policy': "script-src 'self' 'unsafe-inline' 'unsafe-eval'; block-all-mixed-content",
'Referrer-Policy': 'same-origin',
'Permissions-Policy': 'geolocation=(),camera=()',
'vary': 'accept-encoding',
'Content-Encoding': 'gzip',
'Content-Type': 'application/json',
'Transfer-Encoding': 'chunked',
'Date': 'Tue, 24 Aug 2021 13:45:19 GMT',
'Keep-Alive': 'timeout=20',
'Connection': 'keep-alive'
}

Using firebase RestApi to signup users using email and password

I'm creating a project where users need to able to log in to their account and see some data. I'm creating a windows application with unity, so from what I understood from researching, I have to use the firebase RestAPI, not the SDK. I managed to use the realTime database but I'm struggling with the authentication side of things.
I followed this tutorial and used the documentation for signing up users into firebase with the RestAPI. I keep getting a 400 (Bad Request) error. I found this post, where the solution was to use a strong password, but that didn't work.
Since I'm using a not so reliable unity c# package as a client, I tested my code with nodeJs as well. Same error.
My code:
C#
private void SignUpUser(string email, string username, string password)
{
string userData = "{\"email\":\"" + email + "\",\"password\":\"" + password + "\",\"returnSecureToken\":true}";
// Content type is json by default
RestClient.Post<SignResponse>("https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=" + AuthKey, userData).Then(
response =>
{
Debug.Log("Success");
}).Catch(error =>
{
Debug.Log(error);
});
}
Javascript
const axios = require("axios");
axios
.post(
'https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=' + API_KEY,
{
email: "myEmddail#example",
password: "superStrongzi344##",
returnSecureToken: true,
},
{
'Content-Type': 'application/json',
}
)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
Part of response:
response:
{ status: 400,
statusText: 'Bad Request',
headers:
{ expires: 'Mon, 01 Jan 1990 00:00:00 GMT',
pragma: 'no-cache',
date: 'Sun, 10 May 2020 21:09:52 GMT',
'cache-control': 'no-cache, no-store, max-age=0, must-revalidate',
vary: 'X-Origin, Referer, Origin,Accept-Encoding',
'content-type': 'application/json; charset=UTF-8',
server: 'ESF',
'x-xss-protection': '0',
'x-frame-options': 'SAMEORIGIN',
'x-content-type-options': 'nosniff',
'alt-svc':
'h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"', 'accept-ranges': 'none',
connection: 'close',
'transfer-encoding': 'chunked' },
config:
{ url:
'https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=API_KEY',
method: 'post',
data:
'{"email":"myEmddail#example","password":"superStrongzi344##","returnSecureToken":true}',
Is there anything I'm missing?
Thanks
Try enabling registering with e-mail in your firebase console. Also the c# library you're using doesn't seem very reliable and might not be well suited for error handling, I would suggest the native System.net.http library that's built in. An example of a request:
using System.Net.Http;
private static readonly HttpClient client = new HttpClient();
var values = new Dictionary<string, string>
{
{ "thing1", "hello" },
{ "thing2", "world" }
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync("http://www.example.com/recepticle.aspx", content);
var responseString = await response.Content.ReadAsStringAsync();

Missing boundary in request (Error: content-type missing boundary)

I had this proxy:
router.post('/proxy/foo', function (req, res, next) {
const proxy = http.request({
method: 'POST',
port: 4000,
hostname: 'localhost',
path: `/files/foo`,
headers: {
'Content-Type':'multipart/form-data'
}
},
function (resp) {
resp.pipe(res).once('error', next);
});
req.pipe(proxy).once('error', next);
});
I was sending a POST request to this proxy handler using, the following headers:
{ 'content-type': 'multipart/form-data; boundary=--------------------------842381361531134328792158',
'cache-control': 'no-cache',
'postman-token': '1a5daa0b-2643-45bc-accc-3f7f3ced948d',
'user-agent': 'PostmanRuntime/7.1.1',
accept: '*/*',
host: 'localhost:3040',
cookie: 'cdt_app_token=foobar',
'accept-encoding': 'gzip, deflate',
'content-length': '176',
connection: 'keep-alive' }
Given that, I was getting this error:
Error: content-type missing boundary
So I changed it so that it the proxy request used the same headers as the original request, which makes sense:
const proxy = http.request({
method: 'POST',
port: 4000,
hostname: 'localhost',
path: `/files/foo`,
headers: Object.assign({}, req.headers) // <<<<<<<<<
},
function (resp) {
resp.pipe(res).once('error', next);
});
Now it works, because of this header in particular:
'content-type': 'multipart/form-data; boundary=--------------------------842381361531134328792158'
So what is that boundary thing?

Meteor HTTP response content un readable

This Meteor server code uses atmosphere HTTP package. I receive human un readable characters from response.content even though characters are readable fine in the browser.
Why and how to fix that? Thanks
const response = HTTP.call(method, url, {
timeout: 30000,
headers: header,
params: Params,
followRedirects: true
}
);
console.log(response.content);
response header has:
'content-type': 'text/html'
'content-encoding': 'gzip'
request header has:
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "en-US,en;q=0.5",
"Content-Type": "application/x-www-form-urlencoded"

request headers not submitted during post request using the WiFlyHQ lib

using the WiFlyHQ library i try to send an POST request, it seems like the request header get cropped, if i inspect the request on the server i can see the following:
headers: { host: 'localhost:3000', 'content-type': 'application' },
with this setup;
void SendJasonPacket()
{
wifly.open(Server, ServerPort);
wifly.println("POST / HTTP/1.1");
wifly.println("Host: localhost:3000");
wifly.println("Content-type: application/json");
wifly.println("Accept: application/json");
wifly.println("Content-Length: 93");
wifly.println("User-Agent: easyNAM/0.0.1");
wifly.println("{'checkin':{'device_token': '122','card_token': '12312', 'timestamp': '2012-10-29T14:31:03'}}");
wifly.close();
}
i tried a couple of different headers, that's what i got:
headers: { 'user-agent': 'easyNAM/0.0.1', accept: 'application/j' },
headers: { accept: 'application/json', 'user-agent': 'easyNAM/0' },
headers: { host: 'localhost:3000', 'content-type': 'application' },
it seems, that it get cropped after a specific character count, not sure what i did wrong here....
I believe memory is the issue, i ran into the same issue. I am using VS 2012 to build my app and when it reaches 60% it tends to act sporadically.

Resources