我用VS2003 C#做一个程序,需要HTTP POST。但是第一次能成功,第二次就(GetResponse()处)报错提示基础连接已经关闭。请高手帮帮小弟
代码如下:try
{
HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create("http://mmsc.monternet.com");
httpReq.KeepAlive = false;
httpReq.Proxy = new WebProxy("http://10.0.0.172:80");
httpReq.Method = "POST";
httpReq.Timeout = Timeout.Infinite;
httpReq.Accept= "application/vnd.wap.mms-message,text/*,*/*";
httpReq.Headers.Add("Accept-Charset","iso-8859-1, utf-8, iso-10646-ucs-2; q=0.6");
httpReq.ContentType = "application/vnd.wap.mms-message";
// Write Post Dat
httpReq.ContentLength = mms_length;
Stream sReq = httpReq.GetRequestStream();
sReq.Write(tmp,0,tmp.Length);
sReq.Close();
// Get Response
HttpWebResponse httpRsp = (HttpWebResponse)httpReq.GetResponse();//就在这里出错
Stream stream_Response = httpRsp.GetResponseStream();
StreamReader sReader = new StreamReader(stream_Response,Encoding.ASCII);
string str = sReader.ReadToEnd();
sReader.Close();
stream_Response.Close();
httpRsp.Close();
//httpReq.Abort();
MessageBox.Show(str);
}
catch(InvalidOperationException ee)
{
MessageBox.Show("IN one:" + ee.Message);
}
说明:我是通过代理向移动MMSC发送彩信,10.0.0.172:80是CMWAP网关。http://mmsc.monternet.com是MMSC的URL --------------------编程问答-------------------- 沙发一下 --------------------编程问答-------------------- 怎么不理,啊1自己顶一个 --------------------编程问答-------------------- 学习 一下 --------------------编程问答-------------------- 我也有这个问题...高手求帮 --------------------编程问答-------------------- 没看出来,调试一下; --------------------编程问答-------------------- 一个解决方案是在application.config或web.config文件里加入
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true"/>
</settings>
</system.net>
允许系统容忍(tolerant)只以CR或LF结尾的hearder信息
补充:.NET技术 , C#