Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAaron Selonke
10,323 PointsWorking with HTTP in the Browser with C#
Hi there,
I just finished the HTTP basics and thought I would make a little program that automatically logins into a website.
The Objective of the program is to Automatically log-in to my Pinboard account. Although I seems to make contact with the /auth URI and Responds, it seems that this connection is closed or somehow not linked with the last function of opening the browser. When the browser opens, it doesn't seem to know that the program already logged-in.
Any ideas?
static void Main(string[] args)
{
string FormUrl = "https://pinboard.in/auth/";
string PinUserName = "aarondv1";
string PinPassword = "";
string FormParams = string.Format("username={0}&password={1}", PinUserName, PinPassword);
string cookieHeader;
//Three Headers to update
//1) ContentType
//2)Method
//*) Conversion from UTF-8? to ANCI2?
// Not sure that its necessary, bc pinboard might use utf??
//3)ContentLength
WebRequest req = WebRequest.Create(FormUrl);
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
/*Conversion*/
byte[] bytes = Encoding.ASCII.GetBytes(FormParams);
req.ContentLength = bytes.Length;
using (Stream os = req.GetRequestStream())
{
os.Write(bytes, 0, bytes.Length);
}
WebResponse resp = req.GetResponse();
string opend = resp.ResponseUri.ToString();
System.Diagnostics.Process.Start(opend);
}
}
1 Answer
Steven Parker
231,236 PointsAssuming the site maintains login status with a cookie, how do you capture the cookie, and then place it where the browser will find and use it?