我已经在这项任务中挣扎了很长时间,以至于我希望暂缓。
我们在单独的服务器/域上有一个名为Validate的Web服务。
由于相同的域名限制,我想出了代理服务器(代码)来解决它。
以下代码名为Validate.asp,指向webservice:
Set http = Server.CreateObject("msxml2.ServerXMLHTTP")
http.Open "POST", "http://servername1/folder1/folder2/folder3/Validation/Validate", False
http.setRequestHeader "Content-type","application/x-www-form-urlencoded"
http.Send Request.Form
Response.Write http.ResponseText
Response.End
%>
然后下面的代码标记调用Validate.asp。
<!DOCTYPE html>
<html>
<body>
<form>
Enter name: <input id="user" /><br/>
Enter Pass: <input id="pass" /><br/>
<input type="button" value="Get web response via AJAX" onclick="ajaxViaProxy()" />
</form>
<hr/>
Ressponse: <div id="result"></div>
<script type="text/javascript">
function ajaxViaProxy( )
{
var uname = document.getElementById("user").value;
var upass = document.getElementById("pass").value;
var http = new XMLHttpRequest();
http.open("POST", "Validate.asp", true );
http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
http.onreadystatechange=function()
{
if (http.readyState==4 && http.status==200)
{
document.getElementById("result").innerHTML =
"Response from web server was '" + http.responseText + "'";
}
}
http.send("username=" + encodeURIComponent(uname)
+ "&password=" + encodeURIComponent(upass));
}
</script>
</body>
</html>
如果一切顺利,我们应该得到类似下面的答案:
{"Value":{"TokenId":35,"LoginName":"validUser","Created":"2013-12-03T09:53:35","Expires":"2013-12-24T09:53:35","LastUsed":"2013-12-03T09:53:35"},"Status":0,"Message":null}
这是我将下面的代码粘贴到地址栏并点击回车键时得到的确切响应:
http://servername/folder1/folder2/folder3/Validation/Validate?data={"User":"validUserName","Password":"validPassword"}
但是,当我使用标记来调用proxyValidate.asp,而不是使用令牌获取响应时,我得到以下内容:
{"Value":null,"Status":2,"Message":"Invalid username or password"}
有没有人知道我需要在标记或proxyValidate.asp中更改什么,以便在运行代码时,我得到一个格式正确的URL字符串,如下所示?
http://servername/folder1/folder2/folder3/Validation/Validate?data={"User":"validUserName","Password":"validPassword"}
非常感谢