Posted on: 10/25/15 09:30PM
I've been tearing my hair out with this today. I got it working, but only if I manually set the cookie headers in my request using values I grabbed from a WireShark capture of a browser session. As Jerl recommended, I'm trying to rework my app to do proper log in and get the cookies from Gelb instead. Anyone good with C#? This is my code:
string formUrl = "
www.gelbooru.com/index.ph...=login&code=00";HttpWebRequest req = (HttpWebRequest)WebRequest.Create(formUrl);
req.Referer = formUrl;
req.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0";
req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
byte[] bytes = Encoding.ASCII.GetBytes("user=Strahan&pass=xxxxxx&submit=Log%20In");
req.ContentLength = bytes.Length;
using (Stream os = req.GetRequestStream()) os.Write(bytes, 0, bytes.Length);
WebResponse resp = req.GetResponse();
WebHeaderCollection hdr = resp.Headers;
foreach (string headkey in hdr.Keys) Write(headkey + ": " + hdr[headkey]);
I watched the login process using my browser with WireShark. This was the outgoing transmission:
www.miscfiles.org/gelb-browser-out.jpg and the incoming was
www.miscfiles.org/gelb-browser-in.jpg So I ran my app and triggered that code, and it looks like it worked, judging from the inbound response from Gelb.
www.miscfiles.org/gelb-app-out.jpg and
www.miscfiles.org/gelb-app-in.jpgHowever... the code above is set to iterate though the headers and write to my textbox. From what I understand, cookies are sent as header objects titled "Set-Cookie". This is all I got in the textbox though:
Transfer-Encoding: chunked
Connection: keep-alive
Content-Type: text/html
Date: Mon, 26 Oct 2015 02:27:37 GMT
Server: nginx/1.8.0
I can see the cookies Gelb is giving me in Wireshark, but my WebResponse object doesn't see them. Any ideas what I should do? I don't want to keep using the ghetto way if I can avoid it. Thanks.