I'm trying to get a page-scanner going-----to get to the page in question, I first have to login-----in other words----i have to have the cookies saying I've logged in.
I've got this part done.
Next, I take the cookies, and would then need to do a get-----problem is, when I set the method="GET" it won't let me set the cookies (cannot send a content body with this verb type).
Below is my code-----it's dirty but it's just a test so far.
When I change the method to post, it does snag the page, but it snags the top page instead of the page specified by the URL......so Ii'm not sure how to proceed. Iv'e got a working version in Winsock & VB6---but it's a little easier b/c it's all just sending text to the server. I'm trying to make this a web service.
I've got this part done.
Next, I take the cookies, and would then need to do a get-----problem is, when I set the method="GET" it won't let me set the cookies (cannot send a content body with this verb type).
Below is my code-----it's dirty but it's just a test so far.
When I change the method to post, it does snag the page, but it snags the top page instead of the page specified by the URL......so Ii'm not sure how to proceed. Iv'e got a working version in Winsock & VB6---but it's a little easier b/c it's all just sending text to the server. I'm trying to make this a web service.
Visual Basic:
Dim url As String = "http://login.yahoo.com"
Dim result As String = ""
Dim strPost As String = "login=<sniped>&passwd=<sniped>"
Dim myWriter As StreamWriter
Dim objRequest As HttpWebRequest = WebRequest.Create(url)
'post the page
objRequest.Method = "POST"
objRequest.ContentLength = strPost.Length
objRequest.ContentType = "application/x-www-form-urlencoded"
'make sure to init the cookies collection so it recieves the cookies set by a sucessful login
objRequest.CookieContainer = New CookieContainer
'now get teh response stream
Try
myWriter = New StreamWriter(objRequest.GetRequestStream())
myWriter.Write(strPost)
Catch ex As Exception
MsgBox(ex.Message)
Finally
myWriter.Close()
End Try
Dim objResponse As HttpWebResponse = objRequest.GetResponse()
Dim sr As StreamReader
sr = New StreamReader(objResponse.GetResponseStream())
result = sr.ReadToEnd()
sr.Close()
url = "http://basketball.fantasysports.yahoo.com/nba?page=leaguehome&lid=<sniped>"
result = ""
Dim myWriter2 As StreamWriter
Dim objRequest2 As HttpWebRequest = WebRequest.Create(url)
With objRequest2
'.method = get returns error----b/c i can't set cookies
.Method = "POST"
'set the cookies based on the login above
.CookieContainer = objRequest.CookieContainer
Try
myWriter2 = New StreamWriter(.GetRequestStream())
Catch ex As Exception
MsgBox(ex.Message)
Finally
myWriter2.Close()
End Try
Dim objresponse2 As HttpWebResponse = .GetResponse()
Dim sr2 As StreamReader
sr2 = New StreamReader(objresponse2.GetResponseStream())
Dim result2 As String = sr2.ReadToEnd()
sr.Close()
Me.TextBox3.Text = result2
End With