gpt4 book ai didi

javascript - 将 http 请求发送到第三方服务器并通过重定向获取响应

转载 作者:行者123 更新时间:2023-11-28 05:38:04 26 4
gpt4 key购买 nike

我有 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# 上做到这一点?对第三方服务器的请求的限制以及获取重定向并不常见,这使其成为真正的挑战。

最佳答案

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

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

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

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

关于javascript - 将 http 请求发送到第三方服务器并通过重定向获取响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39188821/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com