-
Notifications
You must be signed in to change notification settings - Fork 0
/
Twi.cs
executable file
·52 lines (44 loc) · 1.77 KB
/
Twi.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Net;
namespace potwitter
{
static class Twi
{
/// <summary>
/// アプリケーションのメイン エントリ ポイントです。
/// </summary>
[STAThread]
static void Main(string[] args)
{
if (args.Length < 1)
{
return;
}
string username = System.Configuration.ConfigurationManager.AppSettings["username"];
string password = System.Configuration.ConfigurationManager.AppSettings["password"];
string url = System.Configuration.ConfigurationManager.AppSettings["url"];
Encoding enc = Encoding.UTF8;
StringBuilder sb = new StringBuilder();
sb.Append("status=");
sb.Append(HttpUtility.UrlEncode(String.Join(" ", args), enc));
byte[] data = Encoding.ASCII.GetBytes(sb.ToString());
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.ServicePoint.Expect100Continue = false;
req.Credentials = new System.Net.NetworkCredential(username, password);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
System.IO.Stream stream = req.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();
WebResponse res = req.GetResponse();
System.IO.Stream resStream = res.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(resStream, enc);
string html = sr.ReadToEnd();
sr.Close();
resStream.Close();
}
}
}