【问题标题】:post http request to 3rd party server and get response with redirect将 http 请求发布到 3rd 方服务器并通过重定向获得响应
【发布时间】:2017-01-04 10:56:35
【问题描述】:

我有 asp.net mvc 项目,我需要将表单作为 httpRequestObject 发送。 我已经尝试了几天向第 3 方信用卡清算公司 url 发出简单的 XMLhttp 请求,并使用 XML 格式的重定向返回响应 - 我不在乎重定向是由 iframe 还是弹出 检查了整个互联网的解决方案,在 JavaScript 上尝试过——但据我所知,我无法用 JS 来做,也尝试过 asp.net 和 c#,但对我没有任何作用。 检查了这里的所有解决方案,但仍然没有任何效果。 检查我是否被代理或防火墙等任何方式阻止,这不是问题。

我目前的 JS 代码是 -

function createMPITransaction() {
var terminal_id = "0962832";
var merchant_id = "938";
var user = "my-user";
var password = "my-password";
var url="https://cguat2.creditguard.co.il/xpo/Relay";
var xmlStr = "my string";


var http = new XMLHttpRequest();

http.open("POST",url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader('Access-Control-Allow-Headers', '*');
http.setRequestHeader('withCredentials', true);
http.setRequestHeader('responseType', 'text');

var response = http.responseText;


http.onreadystatechange = function () {//Call a function when the state changes.
    if (http.readyState == 4 && http.status == 200) {
        alert(http.responseText);
    }
}
console.log(xmlStr);
console.log(http);
http.send(xmlStr);

并从控制台获取 -

 XMLHttpRequest {readyState: 1, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, responseURL: ""…}

我可以在 JS 上做到吗? 如果没有,我怎么能在 asp.net c# 上做到这一点? 请求对 3rd 方服务器的限制,并获得重定向并不常见,这使其成为真正的挑战。

【问题讨论】:

    标签: javascript c# asp.net asp.net-mvc redirect


    【解决方案1】:

    就重定向代码而言,您可以查看类似的答案,例如:https://stackoverflow.com/a/3836811/6298965

    您可能仍然缺少的是检查您的请求是否符合规范,或者您实际上遇到了错误,因此您不会被重定向。

    经过初步分析,我猜想api调用可能需要一个jsonxml。

    此外,如果您使用或至少查看 github 实现会更好:https://github.com/mderazon/creditguard-node/blob/master/lib/creditguard.js

    【讨论】:

    • 感谢我看到 gitHub 实现是用 NODE.JS 实现的,所以我可以用其他 JS 库来实现吗?
    • 嗯...您还用 c# 标记了您的问题并要求提供 c# 解决方案。 browserify 有许多不同的方法可以将 node.js 模块与 c# 集成:请参阅其他 example ...顺便说一句,很高兴我的回答很有帮助 ;-) ...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-19
    相关资源
    最近更新 更多