1
頁面不斷重新登錄。我驗證了憑據已傳遞到請求。沒有運氣。請幫忙。我需要在接下來的一兩天內完成。我在這裏失蹤的任何東西?過去兩天我已經去過這個論壇,但無法想象它。對不起,如果這是重複的。HTTP發佈並獲取以下載CSV文件 - 錯誤
Dim response As Net.HttpWebResponse
Dim myURL1 As String
Dim response As Net.HttpWebResponse
Dim myURL1 As String
Dim myURL2 As String
Dim myURL3 As String
Dim cookieJar As New CookieContainer
Dim myReq As Net.HttpWebRequest
Dim strngData as String
' Network Credentials
Dim cred As New System.Net.NetworkCredential ("myLogin", "myPassword", ".genscape.com")
' Login Page URL
myURL1 = https://apps.genscape.com/NAPowerRT/login.jsp
'URL to scrape data
myURL2 = https://apps.genscape.com/NAPowerRT/planthistory.do?
plantid=9976&numDays=1&format=0/genscape-03_26_12-03_27_12-9708.csv
' Action URL in Form with method = POST
myURL3 = "https://apps.genscape.com/NAPowerRT/j_spring_security_check"
myReq = Net.HttpWebRequest.Create(myURL1)
myCache.GetCredential(myURL1, 0, "http")
myReq.Credentials = cred
'Get Cookies
myURL1 = "https://apps.genscape.com/NAPowerRT/login.jsp"
myReq = Net.HttpWebRequest.Create(myURL1)
myReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"
myReq.Method = "GET"
myReq.CookieContainer = cookieJar
myReq.KeepAlive = True
response = myReq.GetResponse
For Each tempCookie As Net.Cookie In response.Cookies
cookieJar.Add(tempCookie)
Next
myReq.GetResponse.Close()
'Sent POST data
myReq = Net.HttpWebRequest.Create(myURL3)
myReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"
myReq.Method = "Post"
myReq.AllowAutoRedirect = True
myReq.ContentType = "text/html"
myReq.Credentials = cred
myReq.CookieContainer = cookieJar
'Send request to URL that has data with cookies from previous GETs
' ----- The below results in login page instead of page where the csv is located
myReq = Net.HttpWebRequest.Create(myURL2)
myReq.Credentials = cred
myReq.Method = "get"
myReq.ContentType = "text/csv"
myReq.Accept = "text/html"
myReq.AllowAutoRedirect = True
myReq.KeepAlive = True
myReq.CookieContainer = cookieJar
'Get the data from the page
response = myReq.GetResponse
Dim streamreponse As Stream = response.GetResponseStream
Dim stream As StreamReader = New StreamReader(response.GetResponseStream())
strngData = stream.ReadToEnd()
response.Close()