Tuesday, March 3, 2009

CURL post from asp.net to php

curlpost.aspx.cs

public string HttpPost(string uri, string parameters)
{
WebRequest webRequest = WebRequest.Create(uri);
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Method = "POST";
byte[] bytes = Encoding.ASCII.GetBytes(parameters);
Stream os = null;
try
{
webRequest.ContentLength = bytes.Length;
os = webRequest.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
}
catch (WebException ex)
{

}
finally
{
if (os != null)
os.Close();
}

try
{
WebResponse webResponse = webRequest.GetResponse();
if (webResponse == null)
{ return null; }
StreamReader sr = new StreamReader(webResponse.GetResponseStream());
return sr.ReadToEnd().Trim();
}
catch (WebException ex)
{

}
return null;
}


objmm.HttpPost("http://phppaghere", "from_number=" + dtVot.Rows[0]["fromphonenumber"].ToString() + "&to_number=" + phonenumber);

No comments: