[C#] 纯文本查看 复制代码
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Windows.Forms;
namespace AiJi
{
public partial class FrmMain : Form
{
public FrmMain() {
InitializeComponent();
}
/// <summary>
/// 发送消息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnGo_Click(object sender, EventArgs e) {
try {
if (!string.IsNullOrEmpty(txtSend.Text)) {
txtChat.AppendText("Me:" + txtSend.Text + "\r\n");
string msg = txtSend.Text;
System.Threading.ThreadPool.QueueUserWorkItem((s) => GoChat(msg));
txtSend.Clear();
}
} catch {
MessageBox.Show("不好意思死鸡了⊙︿⊙重启下程序吧~");
}
}
/// <summary>
/// 请求小黄鸡回复
/// </summary>
/// <param name="msg"></param>
private void GoChat(string msg) {
//设置Post的Data值
Dictionary<string, string> dr = new Dictionary<string, string>();
dr.Add("para", msg);
//请求回复-10秒超时
HttpWebResponse hp = HttpHelper.CreatePostHttpResponse("http://www.xiaohuangji.com/ajax.php", dr, 10000, null, Encoding.UTF8, null);
//输出文本
StreamReader sr = new StreamReader(hp.GetResponseStream(), Encoding.UTF8);
string s = sr.ReadToEnd();
this.Invoke(new MethodInvoker(delegate {
DisplayMsg(s);
}));
}
//回复文本
private void DisplayMsg(string s) {
this.txtChat.AppendText("小贱鸡:" + s + "\r\n");
this.txtChat.Select(txtChat.Text.Length, 0);
this.txtChat.ScrollToCaret();
}
/// <summary>
/// 窗口加载时
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FrmMain_Load(object sender, EventArgs e) {
DisplayMsg("唔,终于开鸡了。\n小贱鸡:你好,我是小贱鸡。o(∩_∩)o");
}
}
}