日期:2014-05-18 浏览次数:21112 次
static string RegularFlowURL = "localhost/test.php";
public static void Check()
{
try
{
System.Net.ServicePointManager.Expect100Continue = false;
Stream instream = null;
StreamReader sr = null;
HttpWebResponse response = null;
HttpWebRequest request = null;
Encoding encoding = Encoding.UTF8;
request = WebRequest.Create(RegularFlowURL) as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = 0;
response = request.GetResponse() as HttpWebResponse;
instream = response.GetResponseStream();
sr = new StreamReader(instream, encoding);
string content = sr.ReadToEnd();
}
catch (Exception ee)
{
MessageBox.Show("访问出错,请稍后再试");
}
}
static string RegularFlowURL = "http://localhost/test.php";
public static void Check()
{
try
{
System.Net.ServicePointManager.Expect100Continue = false;
Stream instream = null;
StreamReader sr = null;
HttpWebResponse response = null;
HttpWebRequest request = null;
Encoding encoding = Encoding.UTF8;
request = WebRequest.Create(RegularFlowURL) as HttpWebRequest;
response = request.GetResponse() as HttpWebResponse;
instream = response.GetResponseStream();
sr = new StreamReader(instream, encoding);
string content = sr.ReadToEnd();
}
catch (Exception ee)
{
MessageBox.Show("访问出错,请稍后再试");
}
}
------解决方案--------------------
如果再有错把 catch 里 ee.Message 打印出来看看是什么内容
------解决方案--------------------
你又不传参数,
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = 0;