当我在Postman中使用表格数据时结果

当我在Postman中使用表格数据时结果

本文介绍了当我在Postman中使用表格数据时结果不确定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用邮递员插件中的x-www-form-urlencoded标签获得结果,但是如果我想从Chrome邮递员插件中的form-data标签中获取结果,则为

I can get the result using x-www-form-urlencoded tab in postman plug-in but case i want to get it from the form-data tab in the postman plug-in in the the chrome.

var express = require('express');
var app = express();
var port = process.env.PORT || 3000;
var http = require('http').Server(app);
var bodyParser = require('body-parser');
var Random = require("random-js")();

app.use(bodyParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

app.post('/TransactionDelay', function(req, res) {

  var SecurityToken=req.body.SecurityToken;
  var SessionID=req.body.SessionID;
  var TimeStamp=Date.now();
  var SecretTransactionKey=req.body.SecretTransactionKey;
  var TransactionID=req.body.TransactionID;
  var BanksTransactionRefID=req.body.BanksTransactionRefID;
  var SessionRequestType=req.body.SessionRequestType;
  var StatusCode=req.body.StatusCode;
  var StatusDescription=req.body.StatusDescription;
  var tag=req.body.tag;

  var dataFile={"SecurityToken":SecurityToken,"SessionID":SessionID,"TimeStamp":TimeStamp,
  "SecretTransactionKey":SecretTransactionKey,"TransactionID":TransactionID,"BanksTransactionRefID":BanksTransactionRefID,
  "SessionRequestType":SessionRequestType,"StatusCode":StatusCode,"StatusDescription":StatusDescription,
  "Tag":tag};

  res.send('TimeStamp : '+dataFile.TimeStamp+'\nTransactionID : '+dataFile.TransactionID+'\nReplyId : 12993784\nStatusCode : '+dataFile.StatusCode+'\nStatusDescription : '+dataFile.StatusDescription+'\nTags :'+dataFile.Tag);

});

 function checkStatusCode(){
  var status=["Confirmed","Failed","Pending"];
  return status[Random.integer(0,2)];
 }
app.listen(port);
console.log('Server started! At http://localhost:' + port);

推荐答案

您正在使用的代码解析 application / x-www-form-urlencoded ,而要发布的是多部分/表单数据,通过邮递员中的表单数据标签

The code you're using, parses application/x-www-form-urlencoded, whereas what's being posted is multipart/form-data via form-data tab in postman

使用强大的

添加此

var formidable = require('formidable');
var util = require('util');
app.post('/TransactionDelay', function(req, res) {
    var form = new formidable.IncomingForm();

    form.parse(req, function(err, fields, files) {
        res.writeHead(200, {
            'content-type': 'text/plain'
        });
        res.write('received upload:\n\n');
        res.end(util.inspect({
            fields: fields,
            files: files
        }));
    });
}

这用于文件上传,或者您有很多参数,在您的情况下没有用

this is used for file upload or u have a lot of parameters , in ur case it's not useful

总之,只需使用 x-www-form-urlencoded 标签:D

In short just use x-www-form-urlencoded tab :D

这篇关于当我在Postman中使用表格数据时结果不确定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 19:53
查看更多