У меня есть следующий код, который я пытаюсь получить HTML-документ. Не уверен, почему это не сработает.
Вот что я захватил из заголовков Live HTTP:
term_code = 201130 & search_type = А & ключевое слово = & kw_scope = все & kw_opt = все & subj_code = BIO & crse_numb = 205 & университетского городка = & инструктор = & instr_session = * & attr_type = * & ПН = на & Вт = на & ср = на & ЧГ = на & Fri = на & сел = на & ВС = на & avail_flag = на
и вот код, который я использую:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
mWC = New WebClient
wbParameters = New NameValueCollection
wbParameters.Add("term_code", "201130")
wbParameters.Add("search_type", "A")
wbParameters.Add("keyword", "")
wbParameters.Add("kw_scope", "all")
wbParameters.Add("kw_opt", "all")
wbParameters.Add("subj_code", "BIO")
wbParameters.Add("crse_numb", "205")
wbParameters.Add("campus", "*")
wbParameters.Add("instructor", "*")
wbParameters.Add("instr_session", "*")
wbParameters.Add("attr_type", "*")
wbParameters.Add("mon", "on")
wbParameters.Add("tue", "on")
wbParameters.Add("wed", "on")
wbParameters.Add("thu", "on")
wbParameters.Add("fri", "on")
wbParameters.Add("sat", "on")
wbParameters.Add("sun", "on")
wbParameters.Add("avail_flag", "on")
mWC.QueryString = wbParameters
Try
mWC.Headers(HttpRequestHeader.UserAgent) = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.0.3705; Media Center PC 4.0; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"
mWC.Headers(HttpRequestHeader.AcceptEncoding) = "gzip, deflate"
mWC.Headers(HttpRequestHeader.Accept) = "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-xpsdocument, */*"
mWC.Headers(HttpRequestHeader.KeepAlive) = False
Try
Dim sResult As String = mWC.DownloadString(New Uri("https://taylor.yc.edu/BANPROD/pkgyc_yccsweb.P_Results"))
MsgBox(sResult)
Catch ex As Exception
MsgBox(ex.InnerException.Message)
Try
Dim sResult As String = mWC.DownloadString(New Uri("https://taylor.yc.edu/BANPROD/pkgyc_yccsweb.P_Search"))
MsgBox(sResult)
Catch ex2 As Exception
MsgBox(ex.Message)
Try
Dim bytResults() As Byte = mWC.UploadValues(New Uri("https://taylor.yc.edu/BANPROD/pkgyc_yccsweb.P_Results"), wbParameters)
Catch ex3 As Exception
MsgBox("Didn't work " & ex3.Message)
End Try
End Try
End Try
Catch ex As Exception
My.Computer.Clipboard.SetText(ex.Message)
MsgBox(ex.Message)
End Try
Try
Dim wbr As HttpWebRequest = WebRequest.Create("https://taylor.yc.edu/BANPROD/pkgyc_yccsweb.P_Results")
wbr.KeepAlive = False
wbr.Timeout = 600000
wbr.ReadWriteTimeout = 600000
wbr.Method = "POST"
wbr.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.0.3705; Media Center PC 4.0; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"
wbr.CookieContainer = New CookieContainer()
'wbr.ContentLength = formData.Length
'Dim requestStream As Stream = wbr.GetRequestStream()
'MsgBox(requestStream.Read)
'requestStream.Close()
MsgBox(wbr.GetResponse().ToString)
Catch ex As Exception
MsgBox(ex.Message)
End Try
Спасибо за вашу помощь! Мне никогда не удавалось заставить веб-клиента работать, так что это был бы для меня хороший прорыв!