Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. <%@ Page Language="C#" %>
  2. <%@ Import Namespace="System.Text" %>
  3. <%@ Import Namespace="System.Net" %>
  4. <%@ Import Namespace="System.IO" %>
  5. <script runat="server">
  6.  
  7.     protected void Page_Load(object sender, EventArgs e)
  8.     {
  9.         string username = "";
  10.         string password = "";
  11.  
  12.         string postData = "PHP_AUTH_USER=" + username;
  13.         postData += ("&PHP_AUTH_PW=" + password);
  14.         byte[] data = System.Text.Encoding.UTF8.GetBytes(postData);
  15.  
  16.         CookieContainer cc = new CookieContainer();//you need
  17.         HttpWebRequest myRequest =
  18.           (HttpWebRequest)WebRequest.Create("your url here");
  19.        
  20.         myRequest.Accept = "*/*";//You don't need this, but just in case :)
  21.         myRequest.Method = "POST";
  22.         myRequest.UserAgent = (string)Request.Browser.Capabilities[""];
  23.         myRequest.ContentType = "application/x-www-form-urlencoded";
  24.         myRequest.ContentLength = data.Length;
  25.         myRequest.CookieContainer = cc;//You need
  26.  
  27.         Stream newStream = myRequest.GetRequestStream();
  28.  
  29.         newStream.Write(data, 0, data.Length);
  30.         newStream.Close();
  31.  
  32.         using (WebResponse wr = myRequest.GetResponse())
  33.         {
  34.             if (((HttpWebResponse)wr).StatusCode == HttpStatusCode.OK)
  35.             {
  36.                 using (newStream = wr.GetResponseStream())
  37.                 {
  38.                     using (StreamReader reader = new StreamReader(newStream))
  39.                     {
  40.                         Response.ClearContent();
  41.                         Response.Write(reader.ReadToEnd());
  42.                     }
  43.                 }
  44.             }
  45.         }
  46.     }
  47. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement