Send Request By Post
//************************************************************** // // MoneyBaby Project - Open source payment processors for .NET // // Copyright 2007-2008 Marcus McConnell and BV Software // www.CodePlex.com/MoneyBaby //************************************************************** using System; using System.Collections.Generic; using System.Text; using System.Web; using System.Net; using System.IO; namespace BVSoftware.MoneyBaby { public class Utilities { private const int DEFAULTTIMEOUT = 100000; public static string SendRequestByPost(string serviceUrl, string postData) { return SendRequestByPost(serviceUrl, postData, null, DEFAULTTIMEOUT); } public static string SendRequestByPost(string serviceUrl, string postData, System.Net.WebProxy proxy, int timeout) { WebResponse resp = null; WebRequest req = null; string response = string.Empty; byte[] reqBytes = null; try { reqBytes = Encoding.UTF8.GetBytes(postData); req = WebRequest.Create(serviceUrl); req.Method = "POST"; req.ContentLength = reqBytes.Length; req.ContentType = "application/x-www-form-urlencoded"; req.Timeout = timeout; if (proxy != null) { req.Proxy = proxy; } Stream outStream = req.GetRequestStream(); outStream.Write(reqBytes, 0, reqBytes.Length); outStream.Close(); resp = req.GetResponse(); StreamReader sr = new StreamReader(resp.GetResponseStream(), Encoding.UTF8, true); response += sr.ReadToEnd(); sr.Close(); } catch { throw; } return response; } } }