davetemplin / web-request

Simplifies making web requests with TypeScript async/await
MIT License
35 stars 8 forks source link

Question: am i using it correctly with multiple hedaders? headers [ {..}, {..} ] #19

Closed tomer-ben-david closed 7 years ago

tomer-ben-david commented 7 years ago

I want to pass 2 headers so I tried:

    const deployRequest = await WebRequest.stream('https://myurl',
        {
            method: 'post',
            headers: [
                {'Content-Type': 'application/zip'},
                {'Authorization': `Bearer ${apiKey}`}
            ]
        });
    fs.createReadStream(zippedSite).pipe(deployRequest);
    const deployResponse = await deployRequest.response;

i'm not sure i'm using the correct format for request headers since i get: 401 Unauthorized and if i use the same headers with curl all is ok.. anything i'm doing wrong?

PS-davetemplin commented 7 years ago

Looks right but I haven't tried this particular scenario myself. Have you tried comparing the working and non-working request/responses using a tool like Fiddler?

tomer-ben-david commented 7 years ago

it's a good idea, thanks.. i will do it next time :) I have resolved it by replacing it with following snippet instead:

                method: 'post',
                headers: [
                    {
                        name: 'content-type',
                        value: 'application/zip'
                    }
                ],
                auth: {
                    bearer: `${apiKey}`
                }
PS-davetemplin commented 7 years ago

Ah, yes, Was just looking at the docs for request (upon which this is based) and your latest looks closer to what they have in their example code. Glad you got it working.