Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@ Page Language="C#" %>
- <%@ Import Namespace="System.Text" %>
- <%@ Import Namespace="System.Net" %>
- <%@ Import Namespace="System.IO" %>
- <script runat="server">
- protected void Page_Load(object sender, EventArgs e)
- {
- string username = "";
- string password = "";
- string postData = "PHP_AUTH_USER=" + username;
- postData += ("&PHP_AUTH_PW=" + password);
- byte[] data = System.Text.Encoding.UTF8.GetBytes(postData);
- CookieContainer cc = new CookieContainer();//you need
- HttpWebRequest myRequest =
- (HttpWebRequest)WebRequest.Create("your url here");
- myRequest.Accept = "*/*";//You don't need this, but just in case :)
- myRequest.Method = "POST";
- myRequest.UserAgent = (string)Request.Browser.Capabilities[""];
- myRequest.ContentType = "application/x-www-form-urlencoded";
- myRequest.ContentLength = data.Length;
- myRequest.CookieContainer = cc;//You need
- Stream newStream = myRequest.GetRequestStream();
- newStream.Write(data, 0, data.Length);
- newStream.Close();
- using (WebResponse wr = myRequest.GetResponse())
- {
- if (((HttpWebResponse)wr).StatusCode == HttpStatusCode.OK)
- {
- using (newStream = wr.GetResponseStream())
- {
- using (StreamReader reader = new StreamReader(newStream))
- {
- Response.ClearContent();
- Response.Write(reader.ReadToEnd());
- }
- }
- }
- }
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement