Post: VB.NET Help - Httpwebrequest/response Post method
12-11-2011, 08:54 PM #1
fill0botto95
You talkin to me?
(adsbygoogle = window.adsbygoogle || []).push({}); Browsing on the web i found this function:

    Public Function PostData(ByRef data As String, ByRef url As String) As String
Dim request As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded"
Dim postData As String = data
request.ContentLength = postData.Length

Dim writer As New StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII)
writer.Write(postData)
writer.Close()

Dim stream As Stream = request.GetResponse().GetResponseStream()
Dim reader As New StreamReader(stream)
Dim response As String = String.Empty
While (response = reader.ReadLine()) IsNot Nothing
response += reader.ReadLine()
End While

Return response
End Function



I saw also that i can use it for example to sign up on youtube.
In this case i have to "post" (send) some strings to the link, example:

    Dim Request As Object = .GetResponse("https://accounts.google.com/NewAccount")
Dim Response As HttpWebResponse = DirectCast(Request, HttpWebResponse)
Dim Html As String = .ProcessResponse(Response)
Dim sb As New StringBuilder
sb.Append("email=" & .UrlEncode(Information.EMail))
sb.Append("&username=" & .UrlEncode(Information.Username))
sb.Append("&country=" & Information.Location)
sb.Append("&postal_code=" & Information.Postal)
sb.Append("&birthday_mon=" & Information.Birthday.Month)
sb.Append("&birthday_day=" & Information.Birthday.Day)
sb.Append("&birthday_yr=" & Information.Birthday.Year)
sb.Append("&gender=" & IIf(Information.Gender = Gender.Male, "m", "f"))
sb.Append("&find_me_via_email=agreed")
sb.Append("&scr=h%3D1024%26w%3D1280%26d%3D24")
sb.Append("&service_key=")
sb.Append("&session_key=")
sb.Append("&current_form=signupForm")
sb.Append("&next=%2F")
sb.Append("&session_token=" & .UrlEncode(.ParseBetween(Html, "XSRF_TOKEN': '", "'", "XSRF_TOKEN': '".Length).Trim))
Request = .GetResponse("https://www.youtube.com/create_account?action_save_user_info=true", sb.ToString)


Here it sends to the server some strings that contains the fields of the registration or...the data lines that the server expects to recive
now the question: How to understand what i have to "post" if i wish to create a httpwebrequest for another website?
(adsbygoogle = window.adsbygoogle || []).push({});
12-11-2011, 09:55 PM #2
You need to LOG the post data with a extension like tamper data for firefox or a program like fiddler. Then modify the code above to what it has.
12-12-2011, 08:10 PM #3
Epic?
Awe-Inspiring
MoBaTeY is right, most people just look at the data and get the fields from there. But this method might not actually work on all websites, especially ones that heavily use AJAX as it won't be able to execute client-side scripts - the WebBrowser control would be the easiest and most maintainable solution or you could look for another framework/control that has support for those features.
12-12-2011, 09:16 PM #4
fill0botto95
You talkin to me?
Originally posted by Epic
MoBaTeY is right, most people just look at the data and get the fields from there. But this method might not actually work on all websites, especially ones that heavily use AJAX as it won't be able to execute client-side scripts - the WebBrowser control would be the easiest and most maintainable solution or you could look for another framework/control that has support for those features.


Originally posted by MoBaTeY View Post
You need to LOG the post data with a extension like tamper data for firefox or a program like fiddler. Then modify the code above to what it has.


thanks, i succeeded in it using tamper data Smile i made a tool that shorts your link with goo.gl, adf . ly, adfoc. us and tiny. cc

The following user thanked fill0botto95 for this useful post:

Epic?
12-13-2011, 09:18 AM #5
Yeah, made one of those before except I made a dll do others can include it in their projects.

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo