vb.net Post login data httpwebrequest and cookies -


im trying login website, works wont redirect when logs in. here code

        dim request webrequest = webrequest.create("http://www.jamiehayles.com/test/login.php")         request.method = "post"          dim postdata string = "username=testing&password=lmao1234"         dim bytearray byte() = encoding.utf8.getbytes(postdata)         request.contenttype = "application/x-www-form-urlencoded"         request.contentlength = bytearray.length          dim datastream stream = request.getrequeststream()         datastream.write(bytearray, 0, bytearray.length)         datastream.close()         dim response webresponse = request.getresponse()         console.writeline(ctype(response, httpwebresponse).statusdescription)         datastream = response.getresponsestream()         dim reader new streamreader(datastream)         dim responsefromserver string = reader.readtoend()         richtextbox1.text = responsefromserver        reader.close()         datastream.close()         response.close() 

my question is, need cookies redirect? , if guys?

take @ you're doing response server:

dim responsefromserver string = reader.readtoend() richtextbox1.text = responsefromserver 

all you're doing reading , placing content of response text box. you're not responding redirect in way.

a "redirect" means server responds specific status code , header in response. status code tells browser response instruction redirect resource. header contains new resource browser should request.

a web browser checks response code/header , performs new request. code doesn't. shows response user, regardless of is.

so, illustrate, normal redirect happens this:

  • browser: i'm requesting resource.
  • server: ok, i've received request, resource want on there.
  • browser: ok, i'm requesting resource on there.
  • server: ok, here go.

your code, however, more this:

  • code: i'm requesting resource.
  • server: ok, i've received request, resource want on there.
  • code: [no further action taken]

the server instructed code, in http-standard way, request new resource. code ignored instruction.

you need check the status code of response, the headers of response, , make new requests accordingly.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -