///
/// したらばの任意のスレに書き込みます。
///
/// ホストアドレスを設定します。
/// このプロパティはrefererにも使用されます。
/// 板名
/// スレ番
public void WriteShitaraba(string dir, int bbs, int key, string name, string mail, string message)
{
bool writeCompleted = true;
try
{
string referer = String.Format("http://j...content-available-to-author-only...r.jp/bbs/read.cgi/{0}/{1}/{2}/", dir, bbs, key);
string UploadStrOrig = String.Format("DIR={0}&BBS={1}&TIME={2}&NAME={3}&MAIL={4}&MESSAGE={5}&KEY={6}&submit=書き込む", dir, bbs, getNowUnixTime(), name, mail, message, key);
//string UploadStr = HttpUtility.UrlEncode(UploadStrOrig, Encoding.GetEncoding("Shift-JIS"));
string UploadStr = new StringBuilder(Uri.EscapeDataString(UploadStrOrig)).ToString();
byte[] UploadStrBytes = Encoding.GetEncoding("Shift-JIS").GetBytes(UploadStrOrig);
Writer = (HttpWebRequest)HttpWebRequest.Create(String.Format("http://j...content-available-to-author-only...r.jp/bbs/write.cgi/{0}/{1}/{2}/", dir, bbs, key));
Writer.Headers.Add("Origin:http://j...content-available-to-author-only...r.jp");
Writer.Host = "jbbs.livedoor.jp";
Writer.Accept = "*/*";
Writer.Referer = referer;
Writer.UserAgent = "Mozilla/5.0";
Writer.KeepAlive = true;
Writer.ContentLength = UploadStrBytes.Length;
Writer.ContentType = "application/x-www-form-urlencoded";
Writer.Method = "POST";
WriterStream = Writer.GetRequestStream();
WriterStream.Write(UploadStrBytes, 0, UploadStrBytes.Length);
}
catch (Exception)
{
MessageBox.Show("エラーが発生しました。やり直してください。");
}
try
{
WriterResponse = (HttpWebResponse)Writer.GetResponse();
}
catch (Exception ex)
{
MessageBox.Show("書き込みに失敗\r\nエラーメッセージは次のとおり:\r\n{0}", ex.Message);
writeCompleted = false;
}
finally
{
if (writeCompleted)
MessageBox.Show("多分書き込んだはず");
}
}
private void buttonWrite_Click(object sender, EventArgs e)
(
try
{
Uri url = new Uri(toolStripTextBoxUrl.Text);
}
catch (UriFormatException)
{
return;
}
//http://j...content-available-to-author-only...r.jp/bbs/read.cgi/internet/14437/1336026627/
System.Text.RegularExpressions.MatchCollection mc =
System.Text.RegularExpressions.Regex.Matches(
toolStripTextBoxUrl.Text, @"http://j...content-available-to-author-only...r.jp/bbs/read.cgi/(?
[a-zA-Z0-9]+)/(?[0-9]+)/(?[0-9]+)/?$");
foreach (System.Text.RegularExpressions.Match m in mc)
{
try
{
//正規表現を用いて頑張って探した文字列を元にレス(dat)を貰いに行ってもらう
WriteShitaraba(m.Groups["dir"].Value, Convert.ToInt32(m.Groups["bbs"].Value), Convert.ToInt32(m.Groups["key"].Value), "名前", "メアドorさげ", "本文");
}
catch (FormatException)
{
MessageBox.Show("Urlが間違っているようです。正しいurlを入力してやり直してください。");
return;
}
}
}