2016-08-28 141 views
1

我有asp.net mvc项目,需要以httpRequestObject形式发送。 我想了几天已经向第三方信用卡清算公司的网址做简单的XMLhttp请求,并取回XML格式的重定向响应 - 我不在乎是否通过iframe或弹出 所做的重定向全部检查互联网的解决方案,试用它的JavaScript - 但据我了解,我不能用JS来做到这一点,尝试过asp.net和c#也没有效果。 检查所有的解决方案,但仍然没有工作。 检查我是否以代理或防火墙的方式被阻止,这不是问题。向第三方服务器发送http请求并获得重定向响应

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

回答

0

至于只是重定向代码而言,你可以看看类似的答案,例如像:https://stackoverflow.com/a/3836811/6298965

,你是什么人仍下落不明是检查你的要求是规格兼容,或者你实际上出现错误,因此您没有重定向。

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

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

+0

感谢 我看到GitHub的实现与Node.js的, 这样我就可以与其他JS库做呢? –

+0

那么...你也用c#标记了你的问题,并要求提供一个c#解决方案。 browserify node.js模块有很多不同的方法可以将它与c#集成在一起:参见这个[example](http://juristr.com/blog/2014/03/integrating-node-with-csharp/).. 。顺带一提我的回答很有帮助;-) ... –

相关问题