jQuery AJAX to C# Web Service ASMX From HTTPS to HTTP Domain



我用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怎么可能知道服务正在调用一个不安全的页面?

附言我做了这项服务,因为我想避免警报页面。

不确定这是否有帮助,但它解决了我在该警报中遇到的类似问题。

我使用ServerCertificateValidationCallback来修复。 并不是说这很重要,但我的类是ASMX C# Web服务(更多内容见下文)

示例如下:

//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()
    {
        //...
    }
}

最新更新