jQuery AJAX到C#Web服务ASMX从HTTPS到HTTP域

时间:2012-06-27 17:17:20

标签: jquery ajax https asmx

我使用Visual Studio(asmx页面)创建一个调用HTTP页面的Web服务:

WebRequest request = WebRequest.Create("http://ws.geonames.org/countryCode?lat=" + lat + "&lng="+lng);

此服务通过HTTPS提供:

    https://mydevdomain.com/geonames/Service1.asmx/getGeoname

现在,当我使用此jQuery代码从https://mydevdomain.com/page.html调用此服务时......

  var request= $.ajax({
      type: "POST",
      url: "https://mydevdomain.com/geonames/Service1.asmx/getGeoname",
      data: "{ 'lat':'"+coordinatesMap[f][1]+"', lng:'"+ coordinatesMap[f][2]+"'}",
      contentType: "application/json; charset=utf-8",
      dataType: "json"
  });

...我在资源管理器上有经典提醒,告诉我有非安全内容! 为什么? jQuery如何知道该服务正在调用非安全页面?

P.S。我做了这项服务,因为我想避开警报页面。

1 个答案:

答案 0 :(得分:0)

不确定这是否会有所帮助,但它修复了我对该警报的类似问题。

我使用 ServerCertificateValidationCallback 进行修复。并不完全重要,但我的课程是ASMX C#WebService(更多下面)

以下示例:

//Force Trust with server
ServicePointManager.ServerCertificateValidationCallback = delegate(
  Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) {return (true); };

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://999.999.99/PI/services/UCP");
request.Headers.Add("SOAPAction", "");
request.ContentType = "text/xml;charset=\"utf-8\"";
request.Accept = "text/xml";
request.Method = "POST";

更多代码 ...

using System;
using System.Collections.Specialized;
using System.Net;
using System.Net.Security;
using System.IO;
using System.Xml;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService]
public class UCPSvc : WebService {

    [WebMethod (Description="Proxy for ACS UCP WebService")]
    public XmlDocument Proxy()
    {
        //...
    }
}