Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "Content-Length" #127

Open
Daniyal83 opened this issue Sep 12, 2019 · 5 comments

Comments

@Daniyal83
Copy link

Daniyal83 commented Sep 12, 2019

Hello. When I use unirest to make a request a get an error ' Invalid value "undefined" for header "Content-Length" '. How can I prevent that? It happens from time to time, but not every time. I'm using node.js on backend for my application. Here is my function

function addTasks(object) {
    return new Promise((resolve, reject) => {
        unirest.post(`${xtmBaseUrl}/rest-api/projects`)
        .headers({"Authorization": xtmToken,
        'Content-Type': 'multipart/form-data'})  
        .field('customerId', object.customerId)
        .field('name', object.name)
        .field('sourceLanguage', object.source)
        .field('targetLanguages', object.target)
        .field('analysisTemplateId', object.templateId)
        .field(withJoinObject)
        .attach(filesObj)
        .end(response => {
            if(response.error) {
                reject(response.error)
            }
            resolve(response.body)
        })
    })
}
@AntoTG
Copy link

AntoTG commented Sep 30, 2019

Hello @Daniyal83 I had the same problem, my solution was update the form-data dependency of unirest-nodejs to the last version (2.5.1) on the package.js of unirest-nodejs

@bambita
Copy link

bambita commented Nov 8, 2019

I am facing the same error. I use "unirest": "^0.6.0" and "form-data": "^3.0.0"
Any idea?

@adishupadhyay
Copy link

Hi All ,
Any update on above mentioned issue? I am facing same problem

@adishupadhyay
Copy link

Hello @Daniyal83 I had the same problem, my solution was update the form-data dependency of unirest-nodejs to the last version (2.5.1) on the package.js of unirest-nodejs

How you updated, its internally used by unirest

@jbw09
Copy link

jbw09 commented Jun 7, 2022

Still getting this error with unirest 0.6.0 and form-data 4.0.0 while trying to upload attachments in Freshdesk. Most annoying part is I can't figure out how to catch it so it keeps stopping program execution -

try {
        unirest.put(url)
        .headers(headers)
        .attach('attachments[]', fs.createReadStream('./FDattachments/' + encodeURIComponent(attachElement.name)))
        .end(function(response){
            //console.log(response.body)
            console.log(response.headers)
            console.log("Response Status : " + response.status)
            if(response.status == 201){
                console.log("Location Header : "+ response.headers['location'])
            }
            else{
                console.log("X-Request-Id :" + response.headers['x-request-id']);
            }
        });
    } catch (err) {
        console.log(err)
    }

Error thrown -

PS C:\Users\jaywi\Downloads\SW Dev\Heroku Node JS\CSQ> node migratemoretest.js > migrate_output.txt
node:_http_outgoing:566
throw new ERR_HTTP_INVALID_HEADER_VALUE(value, name);
^

TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "Content-Length"
at ClientRequest.setHeader (node:_http_outgoing:579:3)
at FormData. (C:\Users\jaywi\Downloads\SW Dev\Heroku Node JS\CSQ\node_modules\unirest\node_modules\form-data\lib\form_data.js:321:13)
at C:\Users\jaywi\Downloads\SW Dev\Heroku Node JS\CSQ\node_modules\unirest\node_modules\form-data\lib\form_data.js:265:7
at C:\Users\jaywi\Downloads\SW Dev\Heroku Node JS\CSQ\node_modules\unirest\node_modules\async\lib\async.js:251:17
at done (C:\Users\jaywi\Downloads\SW Dev\Heroku Node JS\CSQ\node_modules\unirest\node_modules\async\lib\async.js:126:15)
at C:\Users\jaywi\Downloads\SW Dev\Heroku Node JS\CSQ\node_modules\unirest\node_modules\async\lib\async.js:32:16
at C:\Users\jaywi\Downloads\SW Dev\Heroku Node JS\CSQ\node_modules\unirest\node_modules\async\lib\async.js:248:21
at C:\Users\jaywi\Downloads\SW Dev\Heroku Node JS\CSQ\node_modules\unirest\node_modules\async\lib\async.js:572:34
at C:\Users\jaywi\Downloads\SW Dev\Heroku Node JS\CSQ\node_modules\unirest\node_modules\form-data\lib\form_data.js:105:13
at FSReqCallback.oncomplete (node:fs:198:21) {
code: 'ERR_HTTP_INVALID_HEADER_VALUE'
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants