using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Web;
using System.IO;
using System.Web.Script.Serialization;
using System.Text.RegularExpressions;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1(){
InitializeComponent();
}
public string cookie;
private void Form1_Load(object sender, EventArgs e)
{
Form2 gay = new Form2();
gay.Show();
Application.DoEvents();
this.AcceptButton = button1;
try
{
CookieContainer cookies = new CookieContainer();
Uri url = new Uri("http://www.simsimi.com/talk.htm");
HttpWebRequest mbuh = (HttpWebRequest)HttpWebRequest.Create(url);
mbuh.Accept = "*/*";
mbuh.CookieContainer = cookies;
mbuh.Method = WebRequestMethods.Http.Get;
mbuh.Timeout = 70000;
mbuh.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.8 (KHTML, like Gecko) Chrome/23.0.1250.0 Safari/537.8";
mbuh.AllowAutoRedirect = true;
mbuh.KeepAlive = false;
HttpWebResponse respon = (HttpWebResponse)mbuh.GetResponse();
WebHeaderCollection header = (WebHeaderCollection)respon.Headers;
cookie = cookies.GetCookieHeader(respon.ResponseUri);
}
catch (Exception ex)
{
string err = ex.ToString();
Match match = Regex.Match(err, @"The remote name could not be resolved");
if (match.Success)
{
richTextBox1.Text = "tidak dapat tersambung ke internet";
gay.Close();
}
else
{
richTextBox1.Text = "error tidak diketahui";
gay.Close();
}
}
gay.Close();
this.Show();
}
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.SelectionColor = Color.Lime;
richTextBox1.AppendText("Me: " + textBox1.Text+"\r\n");
Application.DoEvents();
string msg = HttpUtility.UrlEncode(textBox1.Text);
Uri url = new Uri("http://www.simsimi.com/func/req?msg=" + msg + "&lc=id&ft=0.0");
try
{
HttpWebRequest mbuh = (HttpWebRequest)HttpWebRequest.Create(url);
mbuh.Host = "www.simsimi.com";
mbuh.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.8 (KHTML, like Gecko) Chrome/23.0.1250.0 Safari/537.8";
mbuh.Accept = "application/json, text/javascript, */*; q=0.01";
mbuh.Headers.Add("Accept-Language", "id,en-us;q=0.7,en;q=0.3");
mbuh.Headers.Add("Accept-Encoding", "gzip, deflate");
mbuh.ContentType = "application/json; charset=utf-8";
mbuh.Headers.Add("X-Requested-With", "XMLHttpRequest");
mbuh.Referer = "http://www.simsimi.com/talk.htm";
mbuh.Headers.Add("Cookie", cookie);
mbuh.KeepAlive = false;
//mbuh.Headers.Add("Connection", "keep-alive");
HttpWebResponse respon = (HttpWebResponse)mbuh.GetResponse();
Stream xx = respon.GetResponseStream();
StreamReader moco = new StreamReader(xx);
string zz = moco.ReadToEnd();
JavaScriptSerializer test = new JavaScriptSerializer();
Dictionary<string, string> mbah = test.Deserialize<Dictionary<string, string>>(zz);
string text;
try
{
text = mbah["response"].ToString();
}
catch (NullReferenceException ex)
{
text = "apa itu kak ? ane gak pernah denger" + ex;
}
catch (Exception)
{
text = "apa itu kak ? tolong ajari ane";
}
text = text.Replace("simi", "ane");
text = text.Replace("simsimi", "ane");
text = text.Replace("Simi", "ane");
richTextBox1.SelectionColor = Color.Red;
richTextBox1.AppendText("Simsimi: " + text + "\r\n");
moco.Close();
textBox1.Clear();
}
catch (Exception ex)
{
Match match = Regex.Match(ex.ToString(), @"The remote name could not be resolved");
if (match.Success)
{
richTextBox1.Text = "tidak dapat tersambung ke internet";
}
else
{
richTextBox1.Text = "error tidak diketahui";
}
}
}
private void button2_Click(object sender, EventArgs e)
{
richTextBox1.Clear();
}
}
}
Comments