I have this code to log in to xing:
class Programm
{
private static HttpWebRequest request;
private static HttpWebResponse response;
public static void Main()
{
//string targetUrl = "/app/forum/seoparser/bpmn/";
string requestUrl = "http://www.xing.com/app/user";
//Diese Parameter werden per Post Methode übergeben
string requestParameter = "login_user_name=" + HttpUtility.UrlEncode("foo")
+ "&login_password=" + HttpUtility.UrlEncode("foo")
+ "&op=login";
//+ "&dest=" + HttpUtility.UrlEncode(targetUrl);
request = (HttpWebRequest)WebRequest.Create(requestUrl);
#region Schreib Werte in den RequestStream der an die URL geschickt wird
byte[] parameter = Encoding.UTF8.GetBytes(requestParameter);
//request.Method = "GET";
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = parameter.Length;
//request.Credentials = CredentialCache.DefaultCredentials;
Stream requestStream = request.GetRequestStream();
requestStream.Write(parameter, 0, parameter.Length);
requestStream.Close();
#endregion
//Holt sich die Antwort
response = (HttpWebResponse)request.GetResponse();
#region Liest die Antwort (ResponseStream) und gibt sie auf der Console aus
Stream responseStream = response.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream);
//Console.WriteLine(streamReader.ReadToEnd());
string result = streamReader.ReadToEnd();
streamReader.Close();
responseStream.Close();
#endregion
#region write to file
TextWriter tw = new StreamWriter("c:/Upload/result.html");
tw.WriteLine(result);
tw.Close();
#endregion
}
}
The result I get is the same page I get, when I type
http://www.xing.com/app/user
into the browser, but not logged in.
When I type this into the browser:
https://www.xing.com/app/user?op=login&login_user_name=foo&login_password=foo
I am getting the correct result - i.e. the response page after loggin in. Even when I logged out before.
How can I log in correctly using .Net?