应该用到哪些类?Socket?给我个大框架吧,不知道从哪写起,怎么站外url post数据,哪些类负责发接,回调什么的,谢谢啦
解决方案 »
- 讨论:大家在开发C#+Oracle .net 3 以上的的项目中,怎么连接数据库?
- 用C#写的Sql代码生成器有点像动軟一样的程序带代码的。
- DropDownButton
- 在XP和Win2003 64位环境下用32位C#程序反射加载系统目录中用C++编写的32位托管程序集时遇到的怪异问题
- 一个关于线程的小问题
- 大侠们,帮帮忙啊,最近在做眼镜性能指标检测的项目,希望做过的朋友指点一下啊,急。。。。
- 高手请教,在线等急!!!!!!!!!!!!!
- c# serialPort
- 插入数据之后在数据库中不显示
- C#中有沒有像vb中的new collection的类型
- Crystal Report不分群组可以Show图表吗?
- ManualResetEvent.WaitOne()是做什么用的?
{
string result = "";
try
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url + "&" + postData);
req.Method = "GET";
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; Maxthon; .NET CLR 1.1.4322; .NET CLR 2.0.50727; Alexa Toolbar)";
req.ContentType = "application/x-www-form-urlencoded"; HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream(), enc);
result = sr.ReadToEnd();
sr.Close();
resp.Close();
}
catch (Exception)
{
result = "";
}
return result;
} public static string PostHtml(string url, string postData, Encoding enc)
{
string result = "";
try
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url + "&" + postData);
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; Maxthon; .NET CLR 1.1.4322; .NET CLR 2.0.50727; Alexa Toolbar)";
req.ContentType = "application/x-www-form-urlencoded";
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream(), enc);
result = sr.ReadToEnd();
sr.Close();
resp.Close();
}
catch (Exception)
{
result = "";
}
return result;
}
//调用
StrData = PubVar.PostHtml(StrData, StrPost, Encoding.Default); if (StrData == "") return CreateXmlDocument("Query Error");
threadpostdata.Start();
void PostData()
{}
我后来这样写了,不知道对不对private static ManualResetEvent allDone = new ManualResetEvent(false); public static void SendPredict(string content)
{
System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(Predict), content);
} private static void Predict(object content)
{
byte[] data = Encoding.UTF8.GetBytes(PostParam(content.ToString())); HttpWebRequest request = WebRequest.Create("http://guba.hexun.com/CallBack.aspx") as HttpWebRequest;
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
request.Timeout = 100000;
request.ContentLength = data.Length;
Stream stream = request.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();
request.BeginGetResponse(new AsyncCallback(PredictCallback), request); allDone.WaitOne();
} private static void PredictCallback(IAsyncResult asynchronousResult)
{
try
{
HttpWebRequest request = asynchronousResult.AsyncState as HttpWebRequest; HttpWebResponse response = request.EndGetResponse(asynchronousResult) as HttpWebResponse;
Stream streamResponse = response.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse, Encoding.Default);
string content = streamRead.ReadToEnd(); streamResponse.Close();
streamRead.Close();
response.Close();
allDone.Set();
}
catch (Exception e)
{
string error = e.ToString();
}
}