首页  >  问答  >  正文

node.js - nodejs如何调用接口发送post请求?

我用过request-promise模块,但没请求成功,现在不知道是接口的问题,还是我代码的问题,求大神给个帮助!谢谢!
var rp = require('request-promise');
var form={};
rp({

    method: 'POST',
    uri: 'http://upfiles1.xxx.com/xxx.asmx/Upload',
    //form:form,
    body:form,
    headers: {
        "content-type" : "multipart/form-data",//"application/x-www-form-urlencoded"
        "content-length":form.length
    }
});
提示 Unhandled rejection RequestError: Error: Argument error, options.body.TypeError: first argument must be a string or Buffer
我现在最有疑问的就是我要post过去的数据那里到底是body呢,还是form?

把上面代码中的body改成form又会提示下面的错误,我怀疑是接口的问题,不知道是不是啊?????
Unhandled rejection StatusCodeError: 500 - "System.Web.HttpRequestValidationException: 从客户端(fileData=&quot;...�e���=�T��<yu#5�����d�3L6o�Y�...&quot;)中检测到有潜在危险的 Request.Form 值。
Unhandled rejection StatusCodeError: 500 - "System.InvalidOperationException: 缺少参数: key。\r\n   在 System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection)\r\n   在 System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()\r\n   在 System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()\r\n"

48|v3.oa.t | at new StatusCodeError (/mnt/webtest/v3.xx.test.xxx.com/node_modules/.1.1.1@request-promise-core/lib/errors.js:32:15)
现在又提示我缺少参数key,我的key已经被我放在form里面了,为嘛还会缺少呢?

淡淡烟草味淡淡烟草味2632 天前1402

全部回复(3)我来回复

  • 我想大声告诉你

    我想大声告诉你2017-07-06 10:37:59

    上代码 我怎么知道你是什么问题

    回复
    0
  • PHP中文网

    PHP中文网2017-07-06 10:37:59

    uri改成url????

    回复
    0
  • 欧阳克

    欧阳克2017-07-06 10:37:59

    从你的域名看来,你是上传文件,上传文件需要使用FormData对象,你往这方面看看,我手机不方便

    回复
    0
  • 取消回复