nodejs - first argument must be a string or Buffer - when using response.write with http.request

前端 未结 8 1950
难免孤独
难免孤独 2020-12-24 11:29

I\'m simply trying to create a node server that outputs the HTTP status of a given URL.

When I try to flush the response with res.write, I get the error: throw new T

8条回答
  •  抹茶落季
    2020-12-24 11:49

    I get this error message and it mentions options.body

    I had this originally

    request.post({
        url: apiServerBaseUrl + '/v1/verify',
        body: {
            email: req.user.email
        }
    });
    

    I changed it to this:

    request.post({
        url: apiServerBaseUrl + '/v1/verify',
        body: JSON.stringify({
            email: req.user.email
        })
    });
    

    and it seems to work now without the error message...seems like bug though.

    I think this is the more official way to do it:

     request.post({
            url: apiServerBaseUrl + '/v1/verify',
            json: true,
            body: {
                email: req.user.email
            }
        });
    

提交回复
热议问题