通过REST Web服务在不同域-asp.net上的用户身份验证

|| 我希望连接到其他域上的Web服务以对用户进行身份验证。 Web服务本身是一种用Java编写的RESTful服务。数据通过JSON传入和传出。 我最初尝试使用jQuery进行连接(请参见下文)
        function Login()
    {
        $.ajax({
        url: \"http://www.externaldomain.com/login/authenticate\",  
        type: \"POST\",
        dataType: \"json\",
        contentType: \"application/json\",
        data: \"{\'emailAddress\':\'bob@bob.com\', \'password\':\'Password1\'}\", 
        success: LoadUsersSuccess,
            error: LoadUsersError
        });         
    }
    function LoadUsersSuccess(){
        alert(1);
    }
    function LoadUsersError(){
        alert(2);
    }
但是,在检查Firebug时,出现了405 Method Not Allowed错误。 在这个阶段,因为这是我第一次真正使用Web服务,所以我真的只是想知道这是否是最好的处理方式?为了找到解决方案,值得坚持使用这种方法,还是我最好是尝试找到服务器端对此问题的答案?如果是这样,是否有人可以发布任何示例? 非常感谢     
已邀请:
在浏览器中进行跨域Web服务调用非常棘手。由于这是一个潜在的安全漏洞,因此浏览器会阻止这些类型的请求。但是,有一种解决方法称为JSONP。如果您使用JSONP而不是纯JSON,则应该能够发出跨域请求。     
好的,要更新我的位置,我签入了Firebug,并在外部服务器上进行了登录,而导致405错误的原因是因为我正在执行Get而不是Post。 我需要做的是发送用户名和密码,然后收到一个GUID,然后将其用于将来的任何请求。我认为通过在代码中使用'type:post \'就足够了,但显然还不够。有人知道我在哪里出问题了吗?就像我说的那样,Web服务的新手以及我从网上寻找的任何尝试都没有产生任何效果。非常感谢     
好的,我已经解决了问题,然后回到C#并在那里进行操作,而不是使用jQuery或JSONP,然后使用Json.Net来处理接收到的数据。这是代码:
protected void uxLogin_Click(object sender, EventArgs e)
{
StringBuilder data = new StringBuilder();
data.Append(\"{\");
data.Append(\"\'emailAddress\': \'\" + uxEmail.Text + \"\', \");
data.Append(\"\'password\': \'\" + uxPassword.Text + \"\'\");
data.Append(\"}\");

byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());
string url = System.Configuration.ConfigurationManager.AppSettings[\"AuthenticationURL\"].ToString();

string JSONCallback = string.Empty;
Uri address = new Uri(url);

// Create the web request  
HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;

// Set type to POST  
request.Method = \"POST\";
request.ContentType = \"application/json\";
// Create a byte array of the data we want to send  

// Set the content length in the request headers  
request.ContentLength = byteData.Length;

// Write data  
using (Stream postStream = request.GetRequestStream())
{
    postStream.Write(byteData, 0, byteData.Length);
}

// Get response  
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
    // Get the response stream  
    StreamReader reader = new StreamReader(response.GetResponseStream());

    // Console application output  
    JSONCallback = reader.ReadToEnd().ToString();
}


if (!String.IsNullOrEmpty(JSONCallback))
{
    JObject jObject = JObject.Parse(JSONCallback);
    if ((bool)jObject[\"loginResult\"] == false)
    {
        string errorMessage = jObject[\"errorMessage\"].ToString();
        int errorCode = (int)jObject[\"errorCode\"];
    }
    else
    {
        string idToken = jObject[\"idToken\"].ToString();
        Session[\"Userid\"] = idToken;
        Response.Redirect(\"~/MyDetails.aspx\");
    }
}
else
{
    uxReturnData.Text = \"The web service request was not successful - no data was returned\";
}
} 不管怎么说,还是要谢谢你 :)     

要回复问题请先登录注册