大佬教程收集整理的这篇文章主要介绍了如何在node.js中发布数据,内容类型=’application / x-www-form-urlencoded’,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
var loginArgs = { data: 'username="xyzzzzz"&"password="abc12345#"',//data: { // 'username': "xyzzzzz",// 'password': "abc12345#",//},headers: { 'User-Agent': 'MYAPI','Accept': 'application/json','Content-Type':'application/x-www-form-urlencoded' } };
并且发布请求是:
client.post("http:/url/rest/login",loginArgs,function(data,responsE){ console.log(loginArgs); if (response.statusCode == 200) { console.log('succesfully logged in,session:',data.msg); }
它总是返回用户名/密码不正确.
在其余的api中,据说请求体应该是:
username='provide user name in url encoded format'&password= "provide password in url encoded format'
application / x-www-form-urlencoded(URL-Encoded Forms)
URL编码的表单很简单:
const request = require('request'); request.post('http:/url/rest/login',{ form: { username: 'xyzzzzz',password: 'abc12345#' } }) // or request.post('http:/url/rest/login').form({ username: 'xyzzzzz',password: 'abc12345#' }) // or request.post({ url: 'http:/url/rest/login',form: { username: 'xyzzzzz',password: 'abc12345#' } },function (err,httpResponse,body) { /* ... */ })
见:https://github.com/request/request#forms
或者,使用请求承诺
const rp = require('request-promise'); rp.post('http:/url/rest/login',password: 'abc12345#' } }).then(...);
以上是大佬教程为你收集整理的如何在node.js中发布数据,内容类型=’application / x-www-form-urlencoded’全部内容,希望文章能够帮你解决如何在node.js中发布数据,内容类型=’application / x-www-form-urlencoded’所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。