Why is .NET Post different from CURL? broken?
NOTE. I fixed the user agent issue and also added an extra byte to fit the length of the content. However, no luck.
I do not understand this. I ran this code below and the json string result was expired (value is not valid).
However the curl code does the same and works. I either get the expected url string or it says I need to wait (from a few seconds to 1 minute).
Why? What is the difference between them? It looks very F% ^ & * that it behaves differently (this is giving me HOURS of problems).
NOTE. The only cookie required by the site is SID (verified). It contains the session ID. The first message activates it and the second command checks the status with the returned json string. Feel free to set the CookieContainer to only use SIDs if you like.
WARNING: You can change the SID to a different value so that other people can activate it. You might want to run the 2nd url to make sure the session id is not in use and expires / invalidates before you start working.
additional note: with curl or in your browser if you do POST then you can insert sid into the .NET cookie container and the second command will work. But executing the first command (POST data) won't work. This is a post feature that I have used for many other sites that require post and it worked so far. Obviously method validation is a big problem and I can see that it is indeed a POST when I execute the first command.
static void Main(string[] args)
{
var cookie = new CookieContainer();
PostData("http://uploading.com/files/get/37e36ed8/", "action=second_page&file_id=9134949&code=37e36ed8", cookie);
Thread.Sleep(4000);
var res = PostData("http://uploading.com/files/get/?JsHttpRequest=12719362769080-xml&action=get_link&file_id=9134949&code=37e36ed8&pass=undefined",
null/*this makes it GET*/, cookie);
Console.WriteLine(res);
/*
curl -b "SID=37468830" -A "DUMMY_User_Aggent" -d "action=second_page&file_id=9134949&code=37e36ed8" "http://uploading.com/files/get/37e36ed8/"
curl -b "SID=37468830" -A "DUMMY_User_Aggent" "http://uploading.com/files/get/?JsHttpRequest=12719362769080-xml&action=get_link&file_id=9134949&code=37e36ed8&pass=undefined"
*/
}
I'm tired of HttpWebRequest / .NET htto clients. I did it with curl (after learning how to set it up in .NET and update). I did it simple and fast and it worked. No stupid problems.
Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);
var curl = new Easy();
curl.SetOpt(CURLoption.CURLOPT_USERAGENT, "DUMMY_User_Aggent");
curl.SetOpt(CURLoption.CURLOPT_COOKIE, "SID=4385743");
curl.SetOpt(CURLoption.CURLOPT_POSTFIELDS, "action=second_page&file_id=9134949&code=37e36ed8");
curl.SetOpt(CURLoption.CURLOPT_URL, "http://uploading.com/files/get/37e36ed8/");
curl.Perform();
curl.SetOpt(CURLoption.CURLOPT_POST, 0);
Easy.WriteFunction wf = new Easy.WriteFunction(OnWriteData);
curl.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
curl.SetOpt(CURLoption.CURLOPT_URL, "http://uploading.com/files/get/?JsHttpRequest=12719362769080-xml&action=get_link&file_id=9134949&code=37e36ed8&pass=undefined");
curl.Perform();
curl.Cleanup();
Curl.GlobalCleanup();
a source to share