"doesn't seem to work" isn't a good error description.
Are you using a CookieContainer in your requests?
Also, please provide some more background information and code.
Yes I'm using a CookieContainer.
The request seems to be made, because I'm viewing the responsestream in a webbrowsercontrol now.
However it seems like it's not gettiing verified or something like that. ?Caching problem?
The variabeles, which I give the value's of the token to read from the source seem to be the right ones.
Some of my code:
Code:
//Get reloadToken & RTVT
HttpWebRequest tokReq = (HttpWebRequest)HttpWebRequest.Create(marketUrl);
tokReq.CookieContainer = cookieContainer;
tokReq.Method = "GET";
tokReq.CachePolicy = noCachePolicy;
//Grabbing source
using (StreamReader sfreader = new StreamReader(tokReq.GetResponse().GetResponseStream()))
{
marketsource = sfreader.ReadToEnd();
}
//Regex pattern's for extracting the token and RTVT from marketsource
string tokenpattern = @"(?:reloadToken.+value="")(?<Token>[^\""]+)";
string rtvtpattern = @"(?:RTVT.+value=')(?<RTVT>[^']+)";
//Extracting reloadToken and RTVT from source
string reloadToken = Regex.Match(marketsource, tokenpattern).Groups["Token"].Value;
string RTVT = Regex.Match(marketsource, rtvtpattern).Groups["RTVT"].Value;
Does a GET request at the page to store the source in a variable, then it looks with RegEx for the reloadToken and RTVT and stores those in a variable too.
Does a POST request at the url and posts the required data, it works. But doing it again (a second time, I'm looking every second with a timer which time it is and when the time is right it does the request again, like once an hour). The second (same) request (but with some different info, reloadToken and RTVT) doesn't have success. And I can't find out why that's happening.
Have you considered that the tokens may change on every request? The page may require you to always send the last token set generated by the page.
Well, what HTTP status code do you get on the second post? I'm kinda sure the server will throw a 403 forbidden if it really expects you to send the last token and you do not.
I'm using a GET request to find the tokens before every POST request, so every POST request it contains fresh tokens. That's why I find this so strange, because the tokens must be the right tokens.
Well, what HTTP status code do you get on the second post? I'm kinda sure the server will throw a 403 forbidden if it really expects you to send the last token and you do not.
The reload tokens do not match. You are sending the request providing the token from an unknown source. Then, the server replies to this request and also provides a reload token in the response. You may need to send the token supplied by the server in the next request - otherwise the server may detect that you are not accessing the resource through a common webbrowser (since there is probably some javascript send on the first request that does the token handling)
This may also apply to other tokens or challenges.
The reload tokens do not match. You are sending the request providing the token from an unknown source. Then, the server replies to this request and also provides a reload token in the response. You may need to send the token supplied by the server in the next request - otherwise the server may detect that you are not accessing the resource through a common webbrowser (since there is probably some javascript send on the first request that does the token handling)
This may also apply to other tokens or challenges.
Hmm yes, you could be right in that, in the original page the request is made by javascript. So yes, the server sends new reloadTokens to the page ofcourse because it's javascript.
But, I already tried to do another request like ~5 seconds after the first bidRequest to another page, so the javascript sended token must be gone, than another GET request to take the 'new' reloadToken's just from the pagesource, so it should be fresh reloadToken's right?
This is how the pagesource reloadTokens like before my first bid:
So I completely receive a new reloadToken and RTVT, but when doing this in my tool it still not works and at the webpage itself it works like it should do.
Maybe I only should do the second GET request of the pagesource at the reloadToken and not the RTVT?
I have currently no time to test it, doing this tonight or tomorrow.
Are you using the reload token to get your new token or are you just reloading the page? If so, you should consider to get a new token using your reloadToken (which may could change after usage).
I'm replying to this thread again as I'm still/again struggling with this problem.
I've suspended the project for some time a decided to continue it.
How it theoretically works right now:
- The user adds items to a ListBox which my program should bid on.
- When clicked at the button a For Each loop will loop through the ListBox and will bid on every Item in the ListBox
How a single (bid)request looks like right now: (this bidrequest is done for each item in the listbox)
- The first thing it does is do a GET request at the market-page and grab the sourcecode
- Then with some regex it extracts the RTVT and the reloadToken from the source
- Then it sends a POST request with the extracted RTVT and reloadToken