Advertisement
TeHead

EasyWeb by TeHead

Aug 24th, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.17 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net;
  6. using System.IO;
  7.  
  8. namespace TeHead
  9. {
  10.     class EasyWeb
  11.     {
  12.         public WebResponse resp = null;
  13.         public static string RespStr = null;
  14.         public static string GET(string URI)
  15.         {
  16.             WebRequest req = null;
  17.             WebResponse resp = null;
  18.             try
  19.             {
  20.                 req = WebRequest.Create(URI);
  21.                 resp = req.GetResponse();
  22.             }
  23.             catch
  24.             {
  25.                 return null;
  26.             }
  27.             Stream stream = resp.GetResponseStream();
  28.             StreamReader sr = new StreamReader(stream);
  29.             string Out = sr.ReadToEnd();
  30.             sr.Close();
  31.             RespStr = Out;
  32.             return Out;
  33.         }
  34.         public static string POST(string URI, string Data)
  35.         {
  36.             WebRequest req = WebRequest.Create(URI);
  37.             WebResponse resp = null;
  38.             req.Method = "POST";
  39.             req.Timeout = 100000;
  40.             req.ContentType = "application/x-www-form-urlencoded";
  41.             byte[] sentData = Encoding.GetEncoding(1251).GetBytes(Data);
  42.             req.ContentLength = sentData.Length;
  43.             Stream sendStream = req.GetRequestStream();
  44.             sendStream.Write(sentData, 0, sentData.Length);
  45.             sendStream.Close();
  46.             try
  47.             {
  48.                 resp = req.GetResponse();
  49.             }
  50.             catch (WebException ex)
  51.             {
  52.                 resp = ex.Response as HttpWebResponse;
  53.             }
  54.             Stream ReceiveStream = resp.GetResponseStream();
  55.             StreamReader sr = new StreamReader(ReceiveStream, Encoding.UTF8);
  56.             Stream stream = resp.GetResponseStream();
  57.             string Out = sr.ReadToEnd();
  58.             sr.Close();
  59.             RespStr = Out;
  60.             return Out;
  61.         }
  62.         public static void SetProxy(string Addr, int Port)
  63.         {
  64.             WebRequest.DefaultWebProxy = new WebProxy(Addr, Port);
  65.         }
  66.         public static string LastResult()
  67.         {
  68.             return RespStr;
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement