无法加载带有httpwebrequest的页面

时间:2016-04-08 05:16:29

标签: vb.net httpwebrequest

我想从以下地址获取航班时刻表:

  

http://fo-apac.ttinteractive.com/Zenith/FrontOffice/(S(nves1yv4xxoia40cmotixof1))/USBangla/en-GB/BookingEngine/SearchFlights?__cnv=tShqK&json= { “BookingPathArguments”:NULL, “OriginDestinations”:[{ “ISOPEN”:假 “DataIdOrigin”:6337, “DataIdDestination”:6707, “日期时间”:“2016-04-27T00: 00:00.000 “}],” TravelerTypes “:[{” DATAID “:1,” TravelerCount “:1},{” DATAID “:2”,TravelerCount “:0},{” DATAID “:3”,TravelerCount” :0}], “货币”:{ “代码”: “BDT”}, “促销码”:NULL, “DisplayRealAvailability”:假, “可见性”:0, “ExtendedSearchDayCount”:3}

如果您将地址粘贴到浏览器地址栏并使用firebug(或任何fiddler),您将看到此页面发送3个jquery ajax调用以带来计划。以下ajax POST实际上是获取计划。

  

http://fo-apac.ttinteractive.com/Zenith/FrontOffice/(S(nves1yv4xxoia40cmotixof1))/USBangla/en-GB/FlexibleFlightStaticAjax/FlexibleFlightListLoadSelectedDays?__cnv=mxw0s

     

PostData:SaleConditionAccepted = false& ExtendedSearchDayCount = 3& DoNotCheckCache = false& AlreadyLoggedIn = false& TempDataGuid = nves1yv4xxoia40cmotixof1& CurrencyCode = BDT& FareBasisDataId =& Travelers [0] [DataId] = 1& Travellers [0] [Count] = 1&安培; UserSelections [0] [SelectedDate] = 2016-04-27T00:00:00&安培; UserSelections [0] [ReferenceDate] = 2016-04-27T00:00:00&安培; UserSelections [0] [DataIdOrigin] = 6337&安培; UserSelections [0] [DataIdDestination] = 6707&安培; UserSelections [0] [GenericClassDataId] =&安培; UserSelections [0] [SelectedSegments] =&安培; JsonPrepareBookingRequest =安培;促销码=

我正在使用httpwebrequest发送请求,但由于未知原因,我错过了会话​​。我使用CookieContainer来保存cookie。我使用以下函数发送httprequest:

    Public Function GetPostWP(ByVal Url As String, ByVal CkCont As CookieContainer, Optional ByVal PostData As String = "", Optional ByVal refSite As String = "") As String
    Dim pStr As String = ""
    Try
        Dim Http As HttpWebRequest = WebRequest.Create(Url)
        If refSite <> "" Then Http.Referer = refSite
        Http.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate")

        Http.CookieContainer = CkCont  'Initial CkCont is Nothing
        Http.KeepAlive = True
        Http.AllowAutoRedirect = True

        'Http.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6"
        Http.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
        Http.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.137 Safari/537.36"

        If PostData <> "" Then
            Http.Method = "POST"
            Http.ContentLength = PostData.Length
            Http.ContentType = "application/x-www-form-urlencoded"

            Dim PostStream As StreamWriter = New StreamWriter(Http.GetRequestStream())
            PostStream.Write(PostData)
            PostStream.Close()
        End If

        Using WebResponse As HttpWebResponse = Http.GetResponse()
            Dim responseStream As Stream = WebResponse.GetResponseStream()

            If (WebResponse.ContentEncoding.ToLower().Contains("gzip")) Then
                responseStream = New GZipStream(responseStream, CompressionMode.Decompress)
            ElseIf (WebResponse.ContentEncoding.ToLower().Contains("deflate")) Then
                responseStream = New DeflateStream(responseStream, CompressionMode.Decompress)
            End If

            Dim reader As StreamReader = New StreamReader(responseStream, Encoding.Default)
            pStr = reader.ReadToEnd()

            responseStream.Close()
        End Using

        tmpCky = CkCont 'tmpCky is a Public CookieContainer Variable to hold cookies for future use.
        GetPostWP = pStr

    Catch ex As Exception
        GetPostWP = "Error : " & ex.Message
    End Try
End Function

    Dim Cky As New CookieContainer
    Dim Txt as String = GetPostWP(PostAddress, Cky, PostData, RefAdd)

    Cky = tmpCky

有人可以分析一下这个页面吗?

0 个答案:

没有答案