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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | class MyWinHttp { private: HINTERNET hSession = NULL, hConnect = NULL, hRequest = NULL; public: MyWinHttp() { printf("생성자\n"); } ~MyWinHttp() { printf("소멸자 뿌잉ㅋ\n"); if (hRequest) { WinHttpCloseHandle(hRequest); hRequest = NULL; } if (hConnect) { WinHttpCloseHandle(hConnect); hConnect = NULL; } if (hSession) { WinHttpCloseHandle(hSession); hSession = NULL; } } public: BOOL Open(LPCSTR lpszVerb, LPCSTR lpszUrl) { URL_COMPONENTS urlComp; wchar_t hostname[128], urlpath[128], extrainfo[128], buf[256], buf2[128]; BOOL bResults = FALSE; if (hSession) return FALSE; MultiByteToWideChar(CP_ACP, 0, lpszVerb, -1, buf, strlen(lpszVerb) * 2); MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, buf2, strlen(lpszUrl) * 2); ZeroMemory(&urlComp, sizeof(urlComp)); urlComp.dwStructSize = sizeof(urlComp); urlComp.dwExtraInfoLength = sizeof(extrainfo); urlComp.dwHostNameLength = sizeof(hostname); urlComp.dwUrlPathLength = sizeof(urlpath); urlComp.lpszHostName = hostname; urlComp.lpszUrlPath = urlpath; urlComp.lpszExtraInfo = extrainfo; if (!WinHttpCrackUrl(buf2, wcslen(buf2), 0, &urlComp)) { return NULL; } wsprintfW(buf2, L"%s%s", urlpath, extrainfo); hSession = WinHttpOpen(L"MyWinHttp", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0); if (hSession) hConnect = WinHttpConnect(hSession, hostname, INTERNET_DEFAULT_HTTP_PORT, 0); if (hConnect) hRequest = WinHttpOpenRequest(hConnect, buf, buf2, NULL, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, 0); return (BOOL)hRequest; } void Close() { if (hRequest) { WinHttpCloseHandle(hRequest); hRequest = NULL; } if (hConnect) { WinHttpCloseHandle(hConnect); hConnect = NULL; } if (hSession) { WinHttpCloseHandle(hSession); hSession = NULL; } } BOOL SetRequestHeader(LPCSTR lpszHeader, LPCSTR lpszValue) { wchar_t buf[1024]; if (hRequest == NULL) return FALSE; wsprintfW(buf, L"%S: %S", lpszHeader, lpszValue); return WinHttpAddRequestHeaders(hRequest, buf, -1, WINHTTP_ADDREQ_FLAG_ADD); } BOOL Send(LPCSTR lpszOptional, DWORD dwOptionalLength) { if (hRequest == NULL || WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, (LPVOID)lpszOptional, dwOptionalLength, dwOptionalLength, 0) == NULL) return FALSE; else return WinHttpReceiveResponse(hRequest, NULL); } char* ResponseBody(char *buffer) { DWORD dwSize, dwRead = 0, dwDownloaded, dwLen; wchar_t buf[1024 * 256]; char *data; if (hRequest == NULL) return FALSE; do { dwSize = 0; if (!WinHttpQueryDataAvailable(hRequest, &dwSize)) { return 0; } data = (LPSTR)malloc(dwSize + 1); if (!data) { dwSize = 0; } else { ZeroMemory(data, dwSize + 1); if (!WinHttpReadData(hRequest, data, dwSize, &dwDownloaded)); else { strcpy(&buffer[dwRead], data); dwRead += dwDownloaded; } free(data); } } while (dwSize > 0); buffer[dwRead] = '\0'; dwLen = MultiByteToWideChar(CP_UTF8, 0, buffer, -1, 0, 0); MultiByteToWideChar(CP_UTF8, 0, buffer, -1, buf, dwLen); dwLen = WideCharToMultiByte(CP_ACP, 0, buf, -1, 0, 0, 0, 0); WideCharToMultiByte(CP_ACP, 0, buf, -1, buffer, dwLen, 0, 0); return buffer; } }; void WriteComment(const char *gallName, const char *articlenum, const char *nick, const char *pw, const char *comment) { char ci_t[64]; char buf[1024 * 256]; MyWinHttp http; wsprintf(buf, "http://gall.dcinside.com/board/view/?id=%s&no=%s", gallName, articlenum); http.Open("GET", buf); http.Send(0, 0); http.ResponseBody(buf); strncpy(ci_t, strstr(buf, "ci_t\" value=\"") + strlen("ci_t\" value=\""), 32); ci_t[32] = '\0'; http.Close(); http.Open("POST", "http://gall.dcinside.com/forms/comment_submit"); wsprintf(buf, "http://gall.dcinside.com/board/view/?id=%s&no=%s&page=1", gallName, articlenum); http.SetRequestHeader("Referer", buf); http.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); http.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0"); http.SetRequestHeader("X-Requested-With", "XMLHttpRequest"); wsprintf(buf, "ci_t=%s&name=%s&password=%s&memo=%s&id=%s&no=%s&best_orgin="</span>, ci_t, nick, pw, comment, gallName, articlenum);</div><div style="padding:0 6px; white-space:pre; line-height:130%"> http.Send(buf, strlen(buf)); printf("%s\n", buf); http.ResponseBody(buf); printf("%s\n", buf); } | cs |
소스는 이러하구욤..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | static WinHttpRequest Winhttp = new WinHttpRequest(); static void WriteComment(string gallID, string articlenum, string nick, string pw, string comment) { Winhttp.Open("GET", "http://gall.dcinside.com/board/view/?id="</span> <span style="color:#0086b3">+ gallID + "&no="</span> <span style="color:#0086b3">+ articlenum); Winhttp.Send(); string ci_t = Encoding.Default.GetString(Winhttp.ResponseBody).Split(new string[] { "ci_t\" value=\"" }, StringSplitOptions.None)[1].Split(new string[] { "\"" }, StringSplitOptions.None)[0]; Winhttp.Open("POST", "http://gall.dcinside.com/forms/comment_submit"); Winhttp.SetRequestHeader("Referer", "http://gall.dcinside.com/board/view/?id="</span> <span style="color:#0086b3">+ gallID + "&no="</span> <span style="color:#0086b3">+ articlenum + "&page=1"); Winhttp.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); Winhttp.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0"); Winhttp.SetRequestHeader("X-Requested-With", "XMLHttpRequest"); Winhttp.Send("ci_t="</span> <span style="color:#0086b3">+ ci_t + "&name="</span> <span style="color:#0086b3">+ nick + "&password="</span> <span style="color:#0086b3">+ pw + "&memo="</span> <span style="color:#0086b3">+ comment + "&id="</span> <span style="color:#0086b3">+ gallID + "&no="</span> <span style="color:#0086b3">+ articlenum + "&best_orgin="</span>);</div><div style="padding:0 6px; white-space:pre; line-height:130%"> } | cs |
같은 방식으로 C#으로 이리 해보면 잘 되는데
C로 저리 하고 post send 한 후에 리스폰스바디 출력해보면
<p>The action you have requested is not allowed.</p>
이렇게 뜹니다..
뭐가 문제일까요
질문할 데가 프갤밖에 없어서 올려봅니다
실력자 형님들 도와주세요 ㅜㅜ
모바일이 아닌 그냥 PC모드로 댓글쓰기 URL로 되나.. 궁금한데.. 갑자기 ㅋㅋ
됨니다..
안 사요
씨샵 몰라서 직접적인 도움 못주는데. 와이어샤크 아님 http message 모니터링 해주는 크롬확장툴 같은거 깔고, 너가 C#에서보낸 http 메세지랑 너가 디시 페이지에서 글올릴때 보내는 메세지랑 비교해봐 뭔가 틀릴수도 있어
와이어샤크 없으면 크롬 가상 vpn 해주는 툴 찾아서 깔아봐라. 가상 vpn 역활로 중간 스니핑 시키는거. ㅇㅇ 그렇게해서 패킷 까봐
ㄴ역활->역할