http://ideone.com/QAcDgR
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Net;
- public class Test
- {
- public static void Main()
- {
- var gallid = "programming";
- var gallnum = ""+ 403098;
- 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;
- HttpWebResponse res = client.GetResponse() as HttpWebResponse;
- var cookCode = res.GetResponseHeader("Set-Cookie");
- int st = cookCode.IndexOf("ci_c="</span><span class="br0" style="color: rgb(0, 153, 0);">) + 5;
- //cic값 추출.
- cookCode = cookCode.Substring(st, 32);
- Console.WriteLine(cookCode);
- StringBuilder PostContent = new StringBuilder();
- //PostData 생성.
- PostContent.Append("id="</span> <span class="sy0" style="color: rgb(51, 153, 51);">+ gallid);
- PostContent.Append("&no="</span> <span class="sy0" style="color: rgb(51, 153, 51);">+ gallnum);
- PostContent.Append("&memo="</span> <span class="sy0" style="color: rgb(51, 153, 51);">+ "test");
- PostContent.Append("&ci_t="</span> <span class="sy0" style="color: rgb(51, 153, 51);">+ cookCode);
- PostContent.Append("&name="</span> <span class="sy0" style="color: rgb(51, 153, 51);">+"dd");
- PostContent.Append("&password="</span> <span class="sy0" style="color: rgb(51, 153, 51);">+ "123123");
- PostContent.Append("&best_orgin:");
- //인코딩
- byte[] bp = Encoding.UTF8.GetBytes(PostContent.ToString());
- HttpWebRequest httpPost = WebRequest.Create("http://gall.dcinside.com/forms/comment_submit") as HttpWebRequest;
- httpPost.Method = "POST";
- httpPost.ContentLength = bp.Length;
- httpPost.Accept = "*/*";
- httpPost.Headers.Add("Accept-Encoding", "gzip,deflate,sdch");
- httpPost.Headers.Add("Accept-Language",
- "ko-KR,ko;q=0.8,en-US;q=0.6,en;q=0.4");
- httpPost.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
- httpPost.Headers.Add("Origin", "http://gall.dcinside.com");
- httpPost.Referer =
- "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;
- httpPost.UserAgent = "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36";
- httpPost.Headers.Add("X-Requested-With", "XMLHttpRequest");
- using (var stream = httpPost.GetRequestStream())
- {
- stream.Write(bp, 0, bp.Length);
- stream.Close();
- }
- res = httpPost.GetResponse() as HttpWebResponse;
- System.IO.StreamReader instream = new System.IO.StreamReader(res.GetResponseStream());
- Console.WriteLine(instream.ReadToEnd());
- }
- }
디시 어떠한 글에 들어가서 댓글을 뿅! 쓰고 꺼지는 코드에요.
재바로 있는 잘 쓰고 있는 코드를 씨샵으로 옮겨볼까 해서요.
음... 그대로 씨샵으로 옮긴것 같은데....
Origin을 "
http://gall.dcinside.com/board/write/?id="+gallid로
바꾸세요
변경- > httpPost.Headers.Add("Origin", "
http://gall.dcinside.com/board/write/?id="
+ gallid); 그래도 안되네요. ㅜㅜ
ㅅㄱ
에요->예요