Advertisement
Guest User

Web Requester

a guest
Aug 27th, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Net;
  10. using System.IO;
  11.  
  12. namespace WebRequest
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.  
  17.         CookieContainer cookieContainer = new CookieContainer();
  18.  
  19.         public Form1()
  20.         {
  21.             InitializeComponent();
  22.         }
  23.  
  24.         private void button1_Click(object sender, EventArgs e)
  25.         {
  26.             string email = "testemail";
  27.             string password = "testkode";
  28.             string url = textBox1.Text;
  29.  
  30.             string PostData = String.Format("email={0}&password={1}", email, password);
  31.  
  32.             HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
  33.             req.CookieContainer = cookieContainer;
  34.             req.Method = "POST";
  35.             req.ContentLength = PostData.Length;
  36.             req.ContentType = "application/x-www-form-urlencoded";
  37.             req.AllowAutoRedirect = true;
  38.             req.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
  39.  
  40.             ASCIIEncoding encoding = new ASCIIEncoding();
  41.             byte[] loginDataBytes = encoding.GetBytes(PostData);
  42.             req.ContentLength = loginDataBytes.Length;
  43.             Stream stream = req.GetRequestStream();
  44.             stream.Write(loginDataBytes, 0, loginDataBytes.Length);
  45.  
  46.             HttpWebResponse webResp = (HttpWebResponse)req.GetResponse();
  47.  
  48.             Stream datastream = webResp.GetResponseStream();
  49.             StreamReader reader = new StreamReader(datastream);
  50.             richTextBox1.AppendText(reader.ReadToEnd() + "\n");
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement