Author | Post | |||
sniperkid |
Im trying to send multiple data (eg username/password/hidden field) to a website but it doesn't seem to work. The following is what i have: Website Code Code: <form> <input type="text" name="txtUsername" /> <input type="password" name="txtPassword /> <input type="hidden" name="txtHidden" value="123" /> </form> vb.Net Code Code: Dim wRequest As HttpWebRequest = HttpWebRequest.Create(sWebsite & "/login.aspx") Dim sPost As String = "" sPost &= "txtUsername=" & sUsername & "&" sPost &= "txtPassword=" & sPassword & "&" sPost &= "txtHidden=123" Dim byteArray As Byte() = Encoding.UTF8.GetBytes(sPost) With wRequest .ContentType = "application/x-www-form-urlencoded" .ContentLength = byteArray.Length .Method = "POST" Dim dataStream As Stream = .GetRequestStream() dataStream.Write(byteArray, 0, byteArray.Length) dataStream.Close() Dim response As WebResponse = .GetResponse() dataStream = response.GetResponseStream() Dim reader As New StreamReader(dataStream) Dim responseFromServer As String = reader.ReadToEnd() msgbox(responseFromServer) 'This gives me the login.aspx source (if something was submitted it would be different) reader.Close() dataStream.Close() response.Close() Anyone have any previous experience in this? Before, the website used to accept GET requests, now its been changed it doesn't . Thanks |
|||
08.03.2011 20:43:46 |
|
|||
quangntenemy |
Does it say wrong username or password or something? Maybe you should check the request sent from your browser to see if you're missing anything. I usually use StreamReader with URLEncoder to send the request. You should easily find an example somewhere on the net |
|||
13.03.2011 13:42:48 |
|
|||
sniperkid |
Doesn't say incorrect anything, just displays the login page as if you first opened it. I made sure i was sending all the vars (saved page locally, changed method to GET then copied vars). I will do some more research |
|||
13.03.2011 16:32:56 |
|
|||
aceldama |
you need to employ a cookie container sniperkid. you can see how that's done in my solution to the lights-out puzzle, but i think this is the code segment you're looking for: Private Sub BrightShadowsLogin() Dim postData As String = _ "retry=&submitted=1&location=%2Fhome.php&" & _ "edit_username=" & BrightShadowsUsername & _ "&edit_password=" & BrightShadowsPassword Dim httpRequest As HttpWebRequest Dim httpResponse As WebResponse Dim dataStream As Stream Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData) Dim strResponse As String httpRequest = CType(WebRequest.Create("http://bright-shadows.net/login.php"), HttpWebRequest) httpRequest.Method = "POST" httpRequest.Timeout = miTimeOut * 1000 httpRequest.AllowAutoRedirect = True httpRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" httpRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)" httpRequest.KeepAlive = True httpRequest.CookieContainer = miCookieJar httpRequest.ContentType = "application/x-www-form-urlencoded" httpRequest.ContentLength = byteArray.Length Try 'TX dataStream = httpRequest.GetRequestStream() dataStream.Write(byteArray, 0, byteArray.Length) dataStream.Close() 'RX httpResponse = httpRequest.GetResponse() dataStream = httpResponse.GetResponseStream() Dim reader As New StreamReader(dataStream) strResponse = reader.ReadToEnd() reader.Close() dataStream.Close() httpResponse.Close() Catch 'Fail End Try End Sub |
|||
21.03.2011 03:27:09 |
|
|||
sniperkid |
mmm maybe its not my code, maybe im not submitting the correct information example of the stuff im submitting is: sPost &= "__LASTFOCUS=&" sPost &= "__EVENTTARGET=&" sPost &= "__EVENTARGUMENT=&" sPost &= "__VIEWSTATE=/wEPDwUJMjE4NDk2NjYxD2QWAmYPZBYCAgMPZBYCAgEPDxYCHgRUZXh0BQMxMDVkZGROTAtiBEeqBpwbVz+Zh68Bcs/LLve+xk195WuB5nowHg==&" sPost &= "__EVENTVALIDATION=/wEWBAK+6ajbDALJ4frZBwL90KKTCAKO9e+RAZmqn2sxUhlSXxifN65YRY4UESnY12T/vJMCV0Jnu+ty&" sPost &= "ctl00$ContentPlaceHolder1$txtUsername=test&" sPost &= "ctl00$ContentPlaceHolder1$txtPassword=test&" sPost &= "ctl00$ContentPlaceHolder1$btnLogin=Login&" sPost &= "recaptcha_challenge_field=03AHJ_VutxztrM0v7h_9hUFQ6PzKwBIHounw_udoJaP8p0BCz93zc7k7EBDPuKyBliXyjo-W31hWJufZb7q0o905fIgkhFrB6zyaAt8WVIcZdBS9bCVMR5zC-gqVKB3n8dohLeCVbx9Fjnfx1NtxYYed-Q4ooK8YAk-w&" sPost &= "recaptcha_response_field=from+ductrop" For testing purposes im putting the recaptcha things in manually. Edit: paste screwy |
|||
Edited by sniperkid on 21.03.2011 20:20:37 | ||||
21.03.2011 20:09:52 |
|
|||
aceldama |
i think you have my email address, as you are on my windows live list. if you need more help, email me and maybe we can get to the bottom of it. (suicidaloptimist) |
|||
25.03.2011 05:00:30 |
|