2
我期待使用API從我的網頁上,目前有一個工作VB的例子,在VBA工作,並希望等效的方法可以在JavascriptWinHttpRequest相當於在Javascript
Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
http.Open "POST", "https://api.net.nz/Service.svc", False
http.setProxy 2, "http://proxynz", ""
http.Option(4) = intSslErrorIgnoreFlags
http.Option(6) = False
http.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
http.setRequestHeader "SOAPAction", "urn:WebServices/ISaleService/CreateSale"
http.send (strXML)
Post = http.responsetext
的代碼來創建我一直在這裏工作,我認爲問題在於VB代碼中的http.setProxy行。
$.ajax({
type: "POST",
url: "https://api.net.nz/Service.svc",
dataType: 'xml',
contentType: "text/xml; charset=\"utf-8\"",
beforeSend: function (xhr) {
xhr.setRequestHeader('SOAPAction', 'urn:WebServices/ISaleService/CreateSale');
},
data: strXML,
async: false,
success: function (data) {alert(data);},
error: function (xhr, status, error) {$('#results').html(error);alert(error)}
});
與上面的代碼我得到一個錯誤信息說
錯誤:NETWORK_ERR:XMLHttpRequest的異常101
更新 還在尋找一個解決方案。我希望有人知道如何引用$ .ajax請求的代理。
- VBA的樣品'https://api.net.nz中/ Service.svc'和JS樣本'https:// api.net.nz/SaleService.svc' – barrowc
是的,我從每個片段中刪除了數據,我再次檢查了我的代碼,它們都是相同的URL。我還添加了從我的JS代碼中獲得的錯誤消息 – Rick