2016-08-28 140 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/).. 。順帶一提我的回答很有幫助;-) ... –

相關問題