我有一个需要将数据传递给 Web 服务 (SMS) 的网页,我尝试使用它WebRequest
来完成这项工作,但是当我使用此类时,会出现以下错误:
Cannot close stream until all bytes are written
在此行之后的行中:
stOut.WriteLine(strNewValue,number,text);
问题是什么?我尝试使用Flush()
但也没有工作
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();
}
}