Advertisement
RieqyNS13

Untitled

May 2nd, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Net;
  10. using System.Web;
  11. using System.IO;
  12. using System.Web.Script.Serialization;
  13. using System.Text.RegularExpressions;
  14. namespace WindowsFormsApplication1
  15. {
  16.     public partial class Form1 : Form
  17.     {
  18.         public Form1(){
  19.        
  20.             InitializeComponent();
  21.         }
  22.         public string cookie;
  23.         private void Form1_Load(object sender, EventArgs e)
  24.         {
  25.             Form2 gay = new Form2();
  26.             gay.Show();
  27.             Application.DoEvents();
  28.             this.AcceptButton = button1;
  29.             try
  30.             {
  31.                 CookieContainer cookies = new CookieContainer();
  32.                 Uri url = new Uri("http://www.simsimi.com/talk.htm");
  33.                 HttpWebRequest mbuh = (HttpWebRequest)HttpWebRequest.Create(url);
  34.                 mbuh.Accept = "*/*";
  35.                 mbuh.CookieContainer = cookies;
  36.                 mbuh.Method = WebRequestMethods.Http.Get;
  37.                 mbuh.Timeout = 70000;
  38.                 mbuh.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.8 (KHTML, like Gecko) Chrome/23.0.1250.0 Safari/537.8";
  39.                 mbuh.AllowAutoRedirect = true;
  40.                 mbuh.KeepAlive = false;
  41.                 HttpWebResponse respon = (HttpWebResponse)mbuh.GetResponse();
  42.                 WebHeaderCollection header = (WebHeaderCollection)respon.Headers;
  43.                 cookie = cookies.GetCookieHeader(respon.ResponseUri);
  44.             }
  45.             catch (Exception ex)
  46.             {
  47.                 string err = ex.ToString();
  48.                 Match match = Regex.Match(err, @"The remote name could not be resolved");
  49.                 if (match.Success)
  50.                 {
  51.  
  52.                     richTextBox1.Text = "tidak dapat tersambung ke internet";
  53.                     gay.Close();
  54.                 }
  55.                 else
  56.                 {
  57.                     richTextBox1.Text = "error tidak diketahui";
  58.                     gay.Close();
  59.                 }
  60.                
  61.             }
  62.             gay.Close();
  63.             this.Show();
  64.            }
  65.  
  66.         private void button1_Click(object sender, EventArgs e)
  67.         {
  68.             richTextBox1.SelectionColor = Color.Lime;
  69.             richTextBox1.AppendText("Me: " + textBox1.Text+"\r\n");
  70.             Application.DoEvents();
  71.             string msg = HttpUtility.UrlEncode(textBox1.Text);
  72.             Uri url = new Uri("http://www.simsimi.com/func/req?msg=" + msg + "&lc=id&ft=0.0");
  73.             try
  74.             {
  75.                 HttpWebRequest mbuh = (HttpWebRequest)HttpWebRequest.Create(url);
  76.                 mbuh.Host = "www.simsimi.com";
  77.                 mbuh.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.8 (KHTML, like Gecko) Chrome/23.0.1250.0 Safari/537.8";
  78.                 mbuh.Accept = "application/json, text/javascript, */*; q=0.01";
  79.                 mbuh.Headers.Add("Accept-Language", "id,en-us;q=0.7,en;q=0.3");
  80.                 mbuh.Headers.Add("Accept-Encoding", "gzip, deflate");
  81.                 mbuh.ContentType = "application/json; charset=utf-8";
  82.                 mbuh.Headers.Add("X-Requested-With", "XMLHttpRequest");
  83.                 mbuh.Referer = "http://www.simsimi.com/talk.htm";
  84.                 mbuh.Headers.Add("Cookie", cookie);
  85.                 mbuh.KeepAlive = false;
  86.                 //mbuh.Headers.Add("Connection", "keep-alive");
  87.                 HttpWebResponse respon = (HttpWebResponse)mbuh.GetResponse();
  88.                 Stream xx = respon.GetResponseStream();
  89.                 StreamReader moco = new StreamReader(xx);
  90.                 string zz = moco.ReadToEnd();
  91.                 JavaScriptSerializer test = new JavaScriptSerializer();
  92.                 Dictionary<string, string> mbah = test.Deserialize<Dictionary<string, string>>(zz);
  93.                 string text;
  94.                 try
  95.                 {
  96.                     text = mbah["response"].ToString();
  97.                 }
  98.                 catch (NullReferenceException ex)
  99.                 {
  100.                     text = "apa itu kak ? ane gak pernah denger" + ex;
  101.                 }
  102.                 catch (Exception)
  103.                 {
  104.                     text = "apa itu kak ? tolong ajari ane";
  105.                 }
  106.                 text = text.Replace("simi", "ane");
  107.                 text = text.Replace("simsimi", "ane");
  108.                 text = text.Replace("Simi", "ane");
  109.                 richTextBox1.SelectionColor = Color.Red;
  110.                 richTextBox1.AppendText("Simsimi: " + text + "\r\n");
  111.                 moco.Close();
  112.                 textBox1.Clear();
  113.             }
  114.             catch (Exception ex)
  115.             {
  116.                 Match match = Regex.Match(ex.ToString(), @"The remote name could not be resolved");
  117.                 if (match.Success)
  118.                 {
  119.  
  120.                     richTextBox1.Text = "tidak dapat tersambung ke internet";
  121.                 }
  122.                 else
  123.                 {
  124.                     richTextBox1.Text = "error tidak diketahui";
  125.                 }
  126.  
  127.  
  128.             }
  129.            
  130.  
  131.         }
  132.  
  133.         private void button2_Click(object sender, EventArgs e)
  134.         {
  135.             richTextBox1.Clear();
  136.         }
  137.     }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement