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

浏览:20日期:2022-09-05

问题描述

我用过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="...�e���=�T��<yu#5�����d�3L6o�Y�...")中检测到有潜在危险的 Request.Form 值。Unhandled rejection StatusCodeError: 500 - 'System.InvalidOperationException: 缺少参数: key。rn 在 System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection)rn 在 System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()rn 在 System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()rn'

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里面了,为嘛还会缺少呢?

问题解答

回答1:

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

回答2:

uri改成url????

回答3:

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

相关文章: