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

前端 未结 8 1966
难免孤独
难免孤独 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:53

    The first argument must be one of type string or Buffer. Received type object

     at write_
    

    I was getting like the above error while I passing body data to the request module.

    I have passed another parameter that is JSON: true and its working.

    var option={
    url:"https://myfirstwebsite/v1/appdata",
    json:true,
    body:{name:'xyz',age:30},
    headers://my credential
    }
    rp(option)
    .then((res)=>{
    res.send({response:res});})
    .catch((error)=>{
    res.send({response:error});})
    

提交回复
热议问题