Hi
ive just started going over this class and gone through a couple of walkthroughs at the top of google, and i understand most of it but i think there is alot of
miss-information im being fed.
heres the best sample i found (with youtube tutorial (@ howtostartprogramming.com)thx) , im just not sure about a couple of things
ill post some code and mark in red what i have questions about.(i replaced the websites)
ok now the website urls where different i just changed them.
the first red line, im thinking its basically the page your are going to get the data for. is that right.
the second red line here could be anything, but in this instance lets say its passing a request as if a search button was pressed with bob in a textbox, is that right.
..........POINT 1 - why would i even need the first red line, is it necessary? i could just send the request right away??!!
third red line, do i really need to set keepalive = true, what if i try and access a bad address, or a server with a serious system hang, it wont time out?????
fourth red line, will the content type change alot or is this usually ok
fifth line, i heard that some sites may need this setting for example with redirects, but is it neccessary normally with a basic site.
and finally what i really dont get is
the sixth line, why is the postrequest.contentlength being set by the length of postdata(ie the site address), should it not be postreq.length????
sorry for the mess
thanks
ive just started going over this class and gone through a couple of walkthroughs at the top of google, and i understand most of it but i think there is alot of
miss-information im being fed.
heres the best sample i found (with youtube tutorial (@ howtostartprogramming.com)thx) , im just not sure about a couple of things
ill post some code and mark in red what i have questions about.(i replaced the websites)
Code:
Dim postData As String = "http://www.abc.com"
Dim tempCookies As New CookieContainer
Dim encoding As New UTF8Encoding
Dim byteData As Byte() = encoding.GetBytes(postData)
Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("http://www.abc.com/search?name=bob"), HttpWebRequest)
postReq.Method = "POST"
postReq.KeepAlive = True
postReq.CookieContainer = tempCookies
postReq.ContentType = "application/x-www-form-urlencoded"
postReq.Referer = "http://www.abc.com/search?name=bob"
postReq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"
postReq.ContentLength = byteData.Length
Dim postreqstream As Stream = postReq.GetRequestStream()
postreqstream.Write(byteData, 0, byteData.Length)
postreqstream.Close()
Dim postresponse As HttpWebResponse
postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
tempCookies.Add(postresponse.Cookies)
logincookie = tempCookies
Dim postreqreader As New StreamReader(postresponse.GetResponseStream())
page = postreqreader.ReadToEnd
the first red line, im thinking its basically the page your are going to get the data for. is that right.
the second red line here could be anything, but in this instance lets say its passing a request as if a search button was pressed with bob in a textbox, is that right.
..........POINT 1 - why would i even need the first red line, is it necessary? i could just send the request right away??!!
third red line, do i really need to set keepalive = true, what if i try and access a bad address, or a server with a serious system hang, it wont time out?????
fourth red line, will the content type change alot or is this usually ok
fifth line, i heard that some sites may need this setting for example with redirects, but is it neccessary normally with a basic site.
and finally what i really dont get is
the sixth line, why is the postrequest.contentlength being set by the length of postdata(ie the site address), should it not be postreq.length????
sorry for the mess
thanks