搜尋
問答 node.js - nodejs如何呼叫介面發送post請求?
node.js - nodejs如何呼叫介面發送post請求?
淡淡烟草味 2017-07-06 10:35:59 查看 1647

0

我用過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裡面了,為嘛還會缺少呢?

Your Answer
提交

3 個答案
0

上程式碼 我怎麼知道你是什麼問題

2017-07-06 10:37:59

提交

0

uri改成url? ? ? ?

2017-07-06 10:37:59

提交

0

從你的網域看來,你是上傳文件,上傳文件需要使用FormData對象,你往這方面看看,我手機不方便

2017-07-06 10:37:59

提交

Hot Tools

vc9-vc14(32+64位元)運行庫合集(連結在下方)

vc9-vc14(32+64位元)運行庫合集(連結在下方)

phpStudy安裝所需運行函式庫集合下載

VC9 32位

VC9 32位

VC9 32位元 phpstudy整合安裝環境運行庫

php程式設計師工具箱完整版

php程式設計師工具箱完整版

程式設計師工具箱 v1.0 php整合環境

VC11 32位

VC11 32位

VC11 32位元 phpstudy整合安裝環境運行庫

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用