I have a webpage that need to pass data to web Service (SMS) and I tried to use WebRequest to do this work but when I use this class the following error appears:
Cannot close stream until all bytes are written in the line after this line :
stOut.WriteLine(strNewValue,number,text); What is the problem? I tried to use Flush() but didn't work either
public class SendSms { public SendSms(string number, string text) { string strNewValue; string strResponse; HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.buymessage.com/ostazSms/send.php"); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; strNewValue = "usr=****&pwd=*****&to={0}&msg={1}"; req.ContentLength = strNewValue.Length; using(StreamWriter stOut = new StreamWriter (req.GetRequestStream(), System.Text.Encoding.Unicode)) { stOut.WriteLine(strNewValue,number,text); } StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream()); strResponse = stIn.ReadToEnd(); stIn.Close(); } }