本文介绍了HttpWebRequest没有响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试获取此URL的内容时
http://www.yellowpages.com.au/qld/gatton/a-12000029- listing.html [ ^ ]
When I try to fetch the content of this URL
http://www.yellowpages.com.au/qld/gatton/a-12000029-listing.html[^]
using System.Net;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(link);
request.AllowAutoRedirect = true;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();
StreamReader objSR;
objSR = new StreamReader(resStream, System.Text.Encoding.GetEncoding("utf-8"));
string sResponse = objSR.ReadToEnd();
我没有从服务器得到任何回应.请帮助我找出发生这种情况的原因.
I don''t get any response from the server. Please help me find out why this happens.
Thanks in advance!
推荐答案
Public Function GetResponce(ByVal url As String) As String
Dim strhtml As String = ""
Dim http As New Chilkat.Http()
Dim unlocked As Boolean = http.UnlockComponent("code to unlock the HTTP component")
If Not unlocked Then
MessageBox.Show("Failed to unlock HTTP component")
Return Nothing
End If
' Do an HTTP GET to get the HTML source of a web page.
' The QuickGetStr and QuickGet methods automatically handle SSL.
Dim html As String = http.QuickGetStr(url)
If html Is Nothing Then
MessageBox.Show(http.LastErrorText)
Else
strhtml = html
End If
Return strhtml
End Function
这篇关于HttpWebRequest没有响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!