GeekZilla
EasyHTTP
EasyHTTP is a simple class which exposes the HTTP functionality of .NET as a number of simpler methods.
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Net; using System.IO; /// <summary> /// Summary description for EasyHTTP /// </summary> public class EasyHTTP { public enum HTTPMethod { HTTP_GET = 0, HTTP_POST = 1 } public EasyHTTP() { // // TODO: Add constructor logic here // } public static string Send(string URL) { return Send(URL, "", HTTPMethod.HTTP_GET, ""); } public static string Send(string URL, string PostData) { return Send(URL, PostData, HTTPMethod.HTTP_GET, ""); } public static string Send(string URL, string PostData, HTTPMethod Method) { return Send(URL, PostData, Method, ""); } public static string Send(string URL, string PostData, HTTPMethod Method, string ContentType) { HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(URL); HttpWebResponse Response; StreamWriter SW = null; StreamReader SR = null; String ResponseData; //Prepare Request Object Request.Method = Method.ToString().Substring(5); //Set form/post content-type if necessary if (Method == HTTPMethod.HTTP_POST && PostData != "" && ContentType == "") { ContentType = "application/x-www-form-urlencoded"; } // Set Content-Type if (ContentType != "") { Request.ContentType = ContentType; Request.ContentLength = PostData.Length; } // Send Request, If Request if (Method == HTTPMethod.HTTP_POST) { try { SW = new StreamWriter(Request.GetRequestStream()); SW.Write(PostData); } catch (Exception Ex) { throw Ex; } finally { SW.Close(); } } // Receive Response try { Response = (HttpWebResponse)Request.GetResponse(); SR = new StreamReader(Response.GetResponseStream()); ResponseData = SR.ReadToEnd(); } catch (WebException Wex) { SR = new StreamReader(Wex.Response.GetResponseStream()); ResponseData = SR.ReadToEnd(); throw new Exception(ResponseData); } finally { SR.Close(); } return ResponseData; } }
Author Barrington Haynes
I have nothing more to say ![]()
Add Comment
Tag Cloud
ajax
asp.net
atlas
authentication
Beta
c#
clr
CSS
dataset
datetime
dojo
dts
email
encryption
enum
event validation
excel
favicon
filesystem
fileupload
flash
fofo
form
full text search
fulltext
Gadget
gaming
gdi
GET
Globalization
javascript
navigation
PaulMarshall
POST
regex
security
seo
sitemap
sql
stored procedure
Strongly Typed Dataset
test
thanks
tips
url
utorrent
validation
vb
vb.net
Vista
VM
VMWare
vs2005
web2
webservice
windows forms
WSS
xml
xna
