我正在测试一个成功访问我的帐户的XML API,我得到了一个响应,但响应似乎是一个没有标签或任何内容的纯文本字符串,甚至没有名称/对值.我需要将响应捕获为XML,以便我可以使用XML标记来标识响应变量.
我使用表单POST将表单中的数据传递给CURL页面,该页面将POST解析为XML格式,然后使用CURL将其发送到API.API是基于XML的,我期望XML响应,而是接收
有所帮助!
CURL REQUEST/RESPONSE PAGE
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$xml = "<?xml version='1.0' encoding='UTF-8'?>";
$xml .= "<request>";
foreach ($_POST as $key => $val) {
$xml .= "<".$key.">". $val ."</".$key.">";
}
$xml .= "<username>user1234</username>";
$xml .= "<password>pass1234</password>";
$xml .= "</request>";
echo "<br/>" . $xml . "<br/><br/>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.beanstream.com/scripts/process_transaction.aspx');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/xml'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); …Run Code Online (Sandbox Code Playgroud) 我不断收到“无法在发送标头后设置标头”的内容,以构建Node / Express API。
问题是在将响应发送到任何地方后,我没有设置标题。我一直在打电话给res.status(xxx).json({})关闭任何条件。
const router = require('express').Router();
router.get('/password/validate/:hash', PasswordController.validate);
router.post('/password/update', PasswordController.update);
Run Code Online (Sandbox Code Playgroud)
这是发生错误的地方。我正在专门致电验证请求。
// Import node packages
const mongoose = require('mongoose');
const Password = require('../models/password');
const User = require('../models/user');
const bcrypt = require('bcryptjs');
const moment = require('moment');
const string = require('../middleware/string_functions')
exports.update = (req, res, next) => {
User.findOne({ email: req.body.email })
.exec()
.then(user => {
if (!user) {
res.status(401).json({
message: 'Cannot retrieve account'
})
}
const expiry = moment().add(30, 'seconds');
const unique_string = string.generate_random(32); …Run Code Online (Sandbox Code Playgroud)