11.09.2014r. - 08:11
Gotowe rozwiązanie wstawiam Tutaj, teraz rodzi się pytanie jak podejrzeć ten kod w WebBroswerze ?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Net;
using System.IO;
namespace PaidVerts
{
/// <summary>
/// Logika interakcji dla klasy MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
protected static CookieContainer Login()
{
string userName = "xXxxXx";
string password = "xXxxXx";
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "Username=" + userName + "&Password=" + password;
byte[] postDataBytes = encoding.GetBytes(postData);
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://TwójLinkDoStrony.pl");
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.ContentLength = postDataBytes.Length;
httpWebRequest.AllowAutoRedirect = false;
using (var stream = httpWebRequest.GetRequestStream())
{
stream.Write(postDataBytes, 0, postDataBytes.Length);
stream.Close();
}
var cookieContainer = new CookieContainer();
using (var httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse())
{
using (var streamReader = new StreamReader(httpWebResponse.GetResponseStream()))
{
foreach (Cookie cookie in httpWebResponse.Cookies)
{
cookieContainer.Add(cookie);
}
}
}
return cookieContainer;
}
}
}