public void sendSingleSMS(String username, String password, String senderid, String mobileNo, String message) { request.ContentLength = 0; String smsservicetype = "singlemsg"; //For single message.

        String query = "username=" + HttpUtility.UrlEncode(username) + "&password=" + HttpUtility.UrlEncode(password) + "&smsservicetype=" + HttpUtility.UrlEncode(smsservicetype) + "&content=" + HttpUtility.UrlEncode(message) + "&mobileno=" + HttpUtility.UrlEncode(mobileNo) + "&senderid=" + HttpUtility.UrlEncode(senderid);
        byte[] byteArray = Encoding.UTF8.GetBytes(query);
        request.ContentType = "application/x-www-form-urlencoded";

        request.ContentLength = byteArray.Length;            
        dataStream = request.GetRequestStream();            
        dataStream.Write(byteArray, 0, byteArray.Length);           
        dataStream.Close();           
        WebResponse response = request.GetResponse();            
        String Status = ((HttpWebResponse)response).StatusDescription;
        dataStream = response.GetResponseStream();
        StreamReader reader = new StreamReader(dataStream);
        string responseFromServer = reader.ReadToEnd();
        reader.Close();
        //byteArray.clear(0);
        //byteArray.length = 0;
        dataStream.Close();
        response.Close();
        //request.ContentType = null;

        request.Abort();
    }

Please Help us from this error,,,,,,

I want to reuse a WebRequest object so that cookies and session would be saved for later request to the server. Below is my code. If i use Post function twice on the second time at

request.ContentLength = byteArray.Length; it will throw an exception

This property cannot be set after writing has started! But as you can see

dataStream.Close(); Should close the writing process! Anybody knows what's going on?

Related posts

Recent Viewed