Need some advice. HTTPwebrequest and tokens.

flann

Regular Member
Joined
Jan 19, 2008
Messages
208
Reaction score
34
I'm almost 2 months learning and building in VB. I know how to use the webbrowser control and make some tools with it. Now i need to switch over to httpwebrequest because of some things like multi-treading and so on. My problem is i can't find any tutorial or example how to use tokens. A simple login is not working without the specific tokens from the website i want to do my shit.

Someone know a good tut or example where i can start? Maybe it is just 1 line of code but i can't get it to work.

Is this something i can use?
Code:
Public Shared Sub AuthorizeRequest ( _
	request As HttpWebRequest, _
	accessToken As String _
)
 
Do you mean cookies or custom headers ?
Share the website url and i will help you.
 
P1nterest
1=i
;)
 
i found something:
Code:
Dim wpLoginToken As String = cutStr(HTML, "<input type=""hidden"" name=""wpLoginToken"" value=""", """") ' finding wpLoginToken parameter
        GetNewForm = wpLoginToken
Not working but this is the right way.

SOme code need to be executed before i send the POST data, so i can extract the token and use it. Right?
 
In high level: send first GET data, parse the token from the HTML and use it in your POST call.
 
In high level: send first GET data, parse the token from the HTML and use it in your POST call.

Sure, i know that. But i can't figure out how to do that.

Low level would be great. ;)


I can fix this with cookiecontainers?
i found this, i wonder if i need to inspect this more or am i on the wrong way .
Code:
private CookieContainer m_CookieContainer = null;
 HttpWebRequest request = (HttpWebRequest)
 WebRequest.Create("http://yoursite.com/yourpage.aspx");
 request.CookieContainer = this.m_CookieContainer;
 request.Timeout = TimeOutTime;
 request.UserAgent = "whateveryouwanthere";
 request.Accept = "text/html";
 request.Referer = "whatever httpreferer if necessary"
 request.KeepAlive = true;
 request.MediaType = "text/html;";

 HttpWebResponse w = null;
 w = (HttpWebResponse) request.GetResponse();
 
Found a better way:
Code:
url = "https://twitter.com/signup"
     HttpRequest = HttpRequest.Create(url)
     HttpRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3"
     HttpRequest.Method = "GET"
     HttpRequest.CookieContainer = cookie_holder
     HttpResponse = HttpRequest.GetResponse()


But still can't get it working. Before my 1st "Dim postData As String =" i can add some code to GET the cookies and close that with "Next" so Next code will/can use the cookies?
 
Last edited:
yeah with pinterest look at the headers and extra cookies that you need to make with your requests

when i get around to it, im going to upload a picture pinning bot with source to learn off
 
Great. Good luck with it.
 
Add a reference to HtmlAgilityPack to your project and use this, you'll need to convert it to VB.NET though.

Code:
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml( -- webpage html you downloaded as a string -- );
string token = doc.DocumentNode.SelectSingleNode("//input[@name='csrfmiddlewaretoken']").Attributes["value"].Value;
doc = null;
 
Back
Top