vb.net - Extracting numbers from a PostRequest -
i posting web form using postreq()
in vb.net.
the response
contains string, "sessionid=wxyz"
, wxyz
4 digits. how can extract these numbers?
here's code:
public sub btn1_click(byval sender system.object, byval e system.eventargs) handles btn1.click dim postdata string = "some post data" dim url string = "http://localhost/form.php" dim tempcookies new cookiecontainer dim encoding new utf8encoding dim bytedata byte() = encoding.getbytes(postdata) dim postreq httpwebrequest = directcast(webrequest.create(url), httpwebrequest) postreq.method = "post" postreq.keepalive = true postreq.cookiecontainer = tempcookies postreq.contenttype = "application/x-www-form-urlencoded" postreq.referer = url 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 stream = postreq.getrequeststream() postreqstream.write(bytedata, 0, bytedata.length) postreqstream.close() dim postresponse httpwebresponse postresponse = directcast(postreq.getresponse(), httpwebresponse) tempcookies.add(postresponse.cookies) logincookie = tempcookies dim postreqreader new streamreader(postresponse.getresponsestream()) dim thepage string = postreqreader.readtoend dim r new system.text.regularexpressions.regex("sessionid=....") end sub
just put part in group, can value using groups
property of match object:
dim r new regex("sessionid=(\d{4})") dim id string = r.match(thepage).groups(1).value
Comments
Post a Comment