Search This Blog

Thursday, December 16, 2010

HttpWebRequest for sms sending by post method

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Net;
using System.Web.Security;
using System.Web.UI.HtmlControls;


public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SendSms();

}
protected void SendSms()
{
try
{

string userid1 = "test&";
string pass1 = "test&";
string appid1 = "test&";
string subappid1 = "test&";
string contenttype1 = "1&";
string selfid1 = "true&";
string from1 = "test&";
string to1 = "9994567831&";
string text1 = "thanks for visit our site&";
string dlrreq1 = "true&";
string alert1 = "1";
string url = "http://smsgateway api url?";
string str_request = "userId=" + userid1 + "pass=" + pass1 + "appid=" + appid1 + "subappid=" + subappid1 + "contenttype=" + contenttype1 + "selfid=" + selfid1 + "from=" + from1 + "to=" + to1 + "text=" + text1 + "dlrreq=" + dlrreq1 + "alert=" + alert1;
string from_sms = "";

StreamWriter sms_writer = null;
HttpWebRequest obj_request = (HttpWebRequest)WebRequest.Create(url + str_request);
obj_request.Method = "post";
obj_request.ContentLength = str_request.Length;
obj_request.ContentType = "application/x-www-form-urlencoded";
sms_writer = new StreamWriter(obj_request.GetRequestStream());
sms_writer.Write(str_request);
sms_writer.Close();
HttpWebResponse obj_response = (HttpWebResponse)obj_request.GetResponse();
using (StreamReader sr = new StreamReader(obj_response.GetResponseStream()))
{
from_sms = sr.ReadToEnd();
sr.Close();
}
}
catch (Exception ex)
{

string str = ex.Message;
lab_mesg.Text = str;
}
}
}

No comments :