2011-11-03 55 views
1

我試圖用C#獲取代碼中的網頁內容,但它給了我錯誤。請幫我解決它。使用c讀取網站內容時出現錯誤#

string url = "http://www.abesoft.org/query.asp 
       searchtype=ANY& 
       query_param=USDOT&original_query_param=NAME& 
       query_string=2134430&original_query_string=NATIONAL GRASS LLC"; 

WebRequest request = WebRequest.Create(url); 
WebResponse response = request.GetResponse(); 
Stream data = response.GetResponseStream(); 
string html = String.Empty; 
using (StreamReader sr = new StreamReader(data)) 
{ 
     html = sr.ReadToEnd(); 
} 

錯誤 - "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."

+0

我認爲這個問題是該網站需要/想要一個安全連接... – Marco

+0

你確定這是此代碼正確的錯誤?你正在使用'http',而不是'https'? – Oded

+0

錯誤是相同的,如果我使用https – Pankaj

回答

1

試試這個:

string url [email protected]"http://www.safersys.org/query.asp? 
       searchtype=ANY&query_type=queryCarrierSnapshot& 
       query_param=USDOT&original_query_param=NAME& 
       query_string=2134430&original_query_string=NATIONAL GRASS LLC"; 

HttpWebRequest request = (HttpWebRequest) HttpWebRequest.Create(url); 
request.AllowAutoRedirect = false; 

WebResponse response = request.GetResponse(); 
Stream data = response.GetResponseStream(); 
string html = String.Empty; 
using (StreamReader sr = new StreamReader(data)) 
{ 
     html = sr.ReadToEnd(); 
} 
相關問題