Monday, December 20, 2010

HOW TO USE XML API

 string Data = " <message-submit-request><username>abc</username><password>abc</password><sender-id>DEMO</sender-id><MType>txt</MType><message-text><text>"+txtMSG.Text+" </text><to>"+num+"</to></message-text></message-submit-request>";
string  newUrl = "http://203.129.101.201/sms/user/XML/send.php";
ApiPost(newUrl, Data);

    public string ApiPost(string url, String strPost)
    {
       try
        {







            try
            {

                ASCIIEncoding encoding = new ASCIIEncoding();



                string furl = url;

                string fmessage = "data=" + strPost;



                byte[] data = encoding.GetBytes(fmessage);



                HttpWebRequest httpreq = (HttpWebRequest)WebRequest.Create(url);

                httpreq.Method = "POST";

                httpreq.ContentType = "application/x-www-form-urlencoded";

                httpreq.ContentLength = data.Length;

                Stream newStream = httpreq.GetRequestStream();

                // Send the data.

                newStream.Write(data, 0, data.Length);







                HttpWebResponse httpres = (HttpWebResponse)httpreq.GetResponse();

                StreamReader sr = new StreamReader(httpres.GetResponseStream());



                string results = sr.ReadToEnd();

                return results;

            }

            catch
            {

                return "0";

            }



        }

        catch
        {

            return "0";

        }

    }