从 URL 下载 XML 的奇怪问题
Odd Issue Downloading XML From URL
我正在尝试使用 SSIS 将 RSS 提要中的数据加载到 SQL 服务器数据库中,但 运行 遇到连接问题。
示例 URL:https://ecf.akb.uscourts.gov/cgi-bin/rss_outside.pl
(可以从网络浏览器正常连接。)
我尝试使用此站点作为模板,https://www.mssqltips.com/sqlservertip/3141/importing-xml-documents-using-sql-server-integration-services/,一切顺利,我能够连接甚至生成一个 .xsd 文件,但是当我转到 运行 它,我收到了关于 SSL\TSL 证书的警告。我还尝试使用内置的 Web 服务任务,但也 运行 遇到尝试下载带有证书的 WSLD 文件的问题。
基于这两个站点尝试另一种途径, and http://palkotools.blogspot.com/2011/06/tutorial-how-to-import-rss-feeds-into.html 我改为尝试使用 C# 脚本任务将 XML 数据下载到文件中,然后再尝试处理。
使用此示例提要 URL,代码运行良好:
WebClient webClient = new WebClient();
webClient.DownloadFile(@"http://feeds.thehollywoodgossip.com/TheHollywoodGossip?format=xml", @"C:\RSS\RSSFile.xml");
然而,当我尝试使用 URL 我需要法庭的时候,它失败了:
WebClient webClient = new WebClient();
webClient.DownloadFile(@"https://ecf.akb.uscourts.gov/cgi-bin/rss_outside.pl?format=xml", @"C:\RSS\RSSFile.xml");
有没有什么different\wrong跟court的URL?我是个C#菜鸟,所以我希望 这是非常简单的事情。你们有没有看到我做错了什么或者需要与好莱坞八卦的例子有所不同 URL?
谢谢!
编辑:这是法庭返回的错误 URL
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
尝试使用 xml linq 进行以下操作。并非每个条目都有 href :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Net;
namespace ConsoleApplication1
{
class Program
{
const string URL = "http://feeds.thehollywoodgossip.com/TheHollywoodGossip?format=xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(URL);
XElement feed = doc.Root;
XNamespace ns = feed.GetDefaultNamespace();
List<Entry> entries = feed.Elements(ns + "entry").Select(x => new Entry()
{
id = (string)x.Element(ns + "id"),
published = (string)x.Element(ns + "published"),
updated = (DateTime)x.Element(ns + "updated"),
href = (string)x.Descendants(ns + "href").FirstOrDefault(),
title = (string)x.Element(ns + "title"),
content = (string)x.Element(ns + "content"),
category = (string)x.Element(ns + "category"),
author = (string)x.Element(ns + "author")
}).ToList();
}
}
public class Entry
{
public string id {get;set;}
public string published {get;set;}
public DateTime updated {get;set;}
public string href {get;set;}
public string title {get;set;}
public string content {get;set;}
public string category {get;set;}
public string author { get; set; }
}
}
尝试在第一行添加这段代码:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
我正在尝试使用 SSIS 将 RSS 提要中的数据加载到 SQL 服务器数据库中,但 运行 遇到连接问题。
示例 URL:https://ecf.akb.uscourts.gov/cgi-bin/rss_outside.pl
(可以从网络浏览器正常连接。)
我尝试使用此站点作为模板,https://www.mssqltips.com/sqlservertip/3141/importing-xml-documents-using-sql-server-integration-services/,一切顺利,我能够连接甚至生成一个 .xsd 文件,但是当我转到 运行 它,我收到了关于 SSL\TSL 证书的警告。我还尝试使用内置的 Web 服务任务,但也 运行 遇到尝试下载带有证书的 WSLD 文件的问题。
基于这两个站点尝试另一种途径, and http://palkotools.blogspot.com/2011/06/tutorial-how-to-import-rss-feeds-into.html 我改为尝试使用 C# 脚本任务将 XML 数据下载到文件中,然后再尝试处理。
使用此示例提要 URL,代码运行良好:
WebClient webClient = new WebClient();
webClient.DownloadFile(@"http://feeds.thehollywoodgossip.com/TheHollywoodGossip?format=xml", @"C:\RSS\RSSFile.xml");
然而,当我尝试使用 URL 我需要法庭的时候,它失败了:
WebClient webClient = new WebClient();
webClient.DownloadFile(@"https://ecf.akb.uscourts.gov/cgi-bin/rss_outside.pl?format=xml", @"C:\RSS\RSSFile.xml");
有没有什么different\wrong跟court的URL?我是个C#菜鸟,所以我希望 这是非常简单的事情。你们有没有看到我做错了什么或者需要与好莱坞八卦的例子有所不同 URL?
谢谢!
编辑:这是法庭返回的错误 URL
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
尝试使用 xml linq 进行以下操作。并非每个条目都有 href :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Net;
namespace ConsoleApplication1
{
class Program
{
const string URL = "http://feeds.thehollywoodgossip.com/TheHollywoodGossip?format=xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(URL);
XElement feed = doc.Root;
XNamespace ns = feed.GetDefaultNamespace();
List<Entry> entries = feed.Elements(ns + "entry").Select(x => new Entry()
{
id = (string)x.Element(ns + "id"),
published = (string)x.Element(ns + "published"),
updated = (DateTime)x.Element(ns + "updated"),
href = (string)x.Descendants(ns + "href").FirstOrDefault(),
title = (string)x.Element(ns + "title"),
content = (string)x.Element(ns + "content"),
category = (string)x.Element(ns + "category"),
author = (string)x.Element(ns + "author")
}).ToList();
}
}
public class Entry
{
public string id {get;set;}
public string published {get;set;}
public DateTime updated {get;set;}
public string href {get;set;}
public string title {get;set;}
public string content {get;set;}
public string category {get;set;}
public string author { get; set; }
}
}
尝试在第一行添加这段代码:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;