http://ideone.com/QAcDgR


  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net;
  6.  
  7.  
  8.  
  9. public class Test
  10. {
  11. public static void Main()
  12. {
  13. var gallid = "programming";
  14. var gallnum = ""+ 403098;
  15.  
  16. HttpWebRequest client = WebRequest.Create("http://gall.dcinside.com/board/view/?id="</span><span class="sy0" style="color: rgb(51, 153, 51);">+gallid+"&no="</span> <span class="sy0" style="color: rgb(51, 153, 51);">+ gallnum) as HttpWebRequest;
  17.  
  18. HttpWebResponse res = client.GetResponse() as HttpWebResponse;
  19.  
  20. var cookCode = res.GetResponseHeader("Set-Cookie");
  21. int st = cookCode.IndexOf("ci_c="</span><span class="br0" style="color: rgb(0, 153, 0);">) + 5;
  22.  
  23. //cic값 추출.
  24. cookCode = cookCode.Substring(st, 32);
  25. Console.WriteLine(cookCode);
  26. StringBuilder PostContent = new StringBuilder();
  27. //PostData 생성.
  28. PostContent.Append("id="</span> <span class="sy0" style="color: rgb(51, 153, 51);">+ gallid);
  29. PostContent.Append("&no="</span> <span class="sy0" style="color: rgb(51, 153, 51);">+ gallnum);
  30. PostContent.Append("&memo="</span> <span class="sy0" style="color: rgb(51, 153, 51);">+ "test");
  31. PostContent.Append("&ci_t="</span> <span class="sy0" style="color: rgb(51, 153, 51);">+ cookCode);
  32. PostContent.Append("&name="</span> <span class="sy0" style="color: rgb(51, 153, 51);">+"dd");
  33. PostContent.Append("&password="</span> <span class="sy0" style="color: rgb(51, 153, 51);">+ "123123");
  34. PostContent.Append("&best_orgin:");
  35. //인코딩
  36. byte[] bp = Encoding.UTF8.GetBytes(PostContent.ToString());
  37.  
  38. HttpWebRequest httpPost = WebRequest.Create("http://gall.dcinside.com/forms/comment_submit") as HttpWebRequest;
  39. httpPost.Method = "POST";
  40. httpPost.ContentLength = bp.Length;
  41. httpPost.Accept = "*/*";
  42. httpPost.Headers.Add("Accept-Encoding", "gzip,deflate,sdch");
  43. httpPost.Headers.Add("Accept-Language",
  44. "ko-KR,ko;q=0.8,en-US;q=0.6,en;q=0.4");
  45. httpPost.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
  46. httpPost.Headers.Add("Origin", "http://gall.dcinside.com");
  47. httpPost.Referer =
  48. "http://gall.dcinside.com/board/view/?id="</span> <span class="sy0" style="color: rgb(51, 153, 51);">+ gallid + "&no="</span> <span class="sy0" style="color: rgb(51, 153, 51);">+ gallnum;
  49. httpPost.UserAgent = "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36";
  50. httpPost.Headers.Add("X-Requested-With", "XMLHttpRequest");
  51.  
  52. using (var stream = httpPost.GetRequestStream())
  53. {
  54. stream.Write(bp, 0, bp.Length);
  55. stream.Close();
  56. }
  57.  
  58. res = httpPost.GetResponse() as HttpWebResponse;
  59. System.IO.StreamReader instream = new System.IO.StreamReader(res.GetResponseStream());
  60. Console.WriteLine(instream.ReadToEnd());
  61. }
  62. }



디시 어떠한 글에 들어가서 댓글을 뿅! 쓰고 꺼지는 코드에요. 

재바로 있는 잘 쓰고 있는 코드를 씨샵으로 옮겨볼까 해서요.

음...  그대로 씨샵으로 옮긴것 같은데....