{"id":1838,"date":"2013-05-20T23:50:00","date_gmt":"2013-05-20T14:50:00","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=1838"},"modified":"2017-01-31T19:44:13","modified_gmt":"2017-01-31T10:44:13","slug":"c-url%eb%a1%9c%eb%b6%80%ed%84%b0-%eb%b0%94%ec%9d%b4%eb%84%88%eb%a6%ac-%eb%8d%b0%ec%9d%b4%ed%84%b0-%eb%8b%a4%ec%9a%b4%eb%a1%9c%eb%93%9c","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=1838","title":{"rendered":"[C++] URL\ub85c\ubd80\ud130 \ubc14\uc774\ub108\ub9ac \ub370\uc774\ud130 \ub2e4\uc6b4\ub85c\ub4dc"},"content":{"rendered":"<p>\uc608\uc804\uc5d0 \ub9cc\ub4e4\uc5b4 \ub193\uc740 \uac83\uc774 \uc788\ub294\ub370.. \ub3c4\ud1b5 \ucc3e\uc744 \uc218\uac00 \uc5c6\uc5b4\uc11c \ub2e4\uc2dc \ub9cc\ub4e4\uc5b4 \ubcf8 \ud568\uc218\uc785\ub2c8\ub2e4. URL \uacbd\ub85c\uc5d0 \uc874\uc7ac\ud558\ub294 \ub370\uc774\ud130\ub97c \ub2e4\uc6b4\ub85c\ub4dc\ud558\uc5ec \ub85c\uceec \ud30c\uc77c\ub85c \uc800\uc7a5\ud574 \uc8fc\ub294 \ud568\uc218\uc785\ub2c8\ub2e4. \uc2e4\uc81c \uac1c\ubc1c\uc5d0 \uc0ac\uc6a9\ud560 \uc694\ub7c9\uc73c\ub85c \uc778\uc790\uac00 \uc81c\ubc95 \ubcf5\uc7a1\ud569\ub2c8\ub2e4.<\/p>\n<pre>DWORD Download(HINTERNET hInternet, char *pszURL, \r\n    char *pszFileName, BYTE *pBuffer) {\r\n    HINTERNET hURL = InternetOpenUrl(hInternet, pszURL, NULL, 0, 0, 0);\r\n    if(hURL == NULL) {\r\n        InternetCloseHandle(hInternet);\r\n        return -2;\r\n    }\r\n\r\n    HANDLE hFile = CreateFile(pszFileName, GENERIC_WRITE, 0, \r\n        NULL, CREATE_ALWAYS,     FILE_ATTRIBUTE_NORMAL, NULL);\r\n    if(hFile == INVALID_HANDLE_VALUE) return -3;\r\n\r\n    DWORD dwSize = 2048;\r\n    DWORD dwRead, dwWritten, dwTotalSize;\r\n\r\n    bool bOK = HttpQueryInfo(hURL, HTTP_QUERY_CONTENT_LENGTH, \r\n        pBuffer, &dwRead, NULL);\r\n    if(!bOK) return -4;\r\n    dwTotalSize = atoi((const char *)pBuffer);\r\n\r\n    do {\r\n        InternetQueryDataAvailable(hURL, &dwSize, 0, 0);\r\n        InternetReadFile(hURL, pBuffer, dwSize, &dwRead);\r\n        WriteFile(hFile, pBuffer, dwRead, &dwWritten, NULL);\r\n    } while(dwRead != 0);\r\n\r\n    InternetCloseHandle(hURL);\r\n    CloseHandle(hFile);\r\n\r\n    return dwTotalSize;\r\n}<\/pre>\n<p>\uc544\ub798\ub294 \uc704\uc758 \ud568\uc218\ub97c \uc9c1\uc811 \uc0ac\uc6a9\ud558\ub294 \ucf54\ub4dc\uc785\ub2c8\ub2e4.<\/p>\n<pre>HINTERNET hInternet = InternetOpen(\"MyAGENT\", INTERNET_OPEN_TYPE_PRECONFIG, \r\n    NULL, NULL, 0);\r\nif(hInternet == NULL) return 0;\r\n\r\nBYTE *pBuffer = new BYTE[1024*1024];\r\nDWORD dwTotalSize;\r\n \r\ndwTotalSize = Download(hInternet, \"http:\/\/www.s.com\/a.zip\", \"c:\/a.zip\", pBuffer);\r\nprintf(\"TotalSize: %d\\n\", dwTotalSize);\r\n\r\ndwTotalSize = Download(hInternet, \"http:\/\/www.s.com\/b.zip\", \"c:\/b.zip\", pBuffer);\r\nprintf(\"TotalSize: %d\\n\", dwTotalSize);\r\n\r\ndelete [] pBuffer;\r\nInternetCloseHandle(hInternet);<\/pre>\n<p>1\ubc88 \ucf54\ub4dc\uc5d0\uc11c\ucc98\ub7fc \uac00\uc7a5\uba3c\uc800 hInternet \uac1d\uccb4\ub97c \ub9cc\ub4ed\ub2c8\ub2e4. \uc774 \uac1d\uccb4\ub97c \uc7ac\ud65c\uc6a9\ud558\uc5ec \ub2e4\uc218\uc758 URL\uc744 \ud1b5\ud574 \ud30c\uc77c\uc744 \ub2e4\uc6b4\ub85c\ub4dc\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. 5\ubc88 \ucf54\ub4dc\ub294 \ud30c\uc77c\uc744 \ub2e4\uc6b4\ub85c\ub4dc\ud558\ub294\ub370 \uc0ac\uc6a9\ud558\ub294 \ubc84\ud37c\uc785\ub2c8\ub2e4. Download \ud568\uc218\ub97c \uc5ec\ub7ec\ubc88 \uc0ac\uc6a9\ud560 \uac83\uc744 \ub300\ube44\ud558\uc5ec \ubc84\ud37c\ub97c \uc7ac\ud65c\uc6a9\ud560 \uc218 \uc788\ub3c4\ub85d \ud558\uc600\uc2b5\ub2c8\ub2e4. \ub610\ud55c Downoad \ud568\uc218\uc758 \uacb0\uacfc\uac12\uc740 \ub2e4\uc6b4\ub85c\ub4dc\ub41c \ubc14\uc774\ub108\ub9ac \ub370\uc774\ud130\uc758 \uc804\uccb4 \ubc14\uc774\ud2b8 \uc218\uc785\ub2c8\ub2e4. \uc74c\uc218\uc778 \uacbd\uc6b0 ERROR\ub85c \uac04\uc8fc\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. 14\ubc88\uacfc 15\ubc88 \ucf54\ub4dc\ucc98\ub7fc \uc0ac\uc6a9\ud55c \ub9ac\uc18c\uc2a4\ub294 \ubc18\ud658\ud569\ub2c8\ub2e4.<\/p>\n<p>\ucd94\uac00\ub85c \uc544\ub798\uc758 Download2 \ud568\uc218\ub294 \ub2e4\uc6b4\ub85c\ub4dc\ub41c \ub370\uc774\ud130\ub97c \ud30c\uc77c\ub85c \uae30\ub85d\ud558\uc9c0 \uc54a\uace0 \uba54\ubaa8\ub9ac \ubc84\ud37c\uc5d0 \uc800\uc7a5\ud558\ub294 \ud568\uc218\uc785\ub2c8\ub2e4. \ub2e4\uc6b4\ub85c\ub4dc\ub41c \ub370\uc774\ud130\ub97c \ud30c\uc77c\uc5d0 \uc800\uc7a5\ud558\uc9c0 \uc54a\uace0 \ubc14\ub85c \uba54\ubaa8\ub9ac \uc0c1\uc5d0\uc11c \uc0ac\uc6a9\ud558\uace0\uc790 \ud560\ub54c \uc0ac\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<pre>DWORD Download2(HINTERNET hInternet, char *pszURL, BYTE *pBuffer) {\r\n    HINTERNET hURL = InternetOpenUrl(hInternet, pszURL, NULL, 0, 0, 0);\r\n    if(hURL == NULL) {\r\n        InternetCloseHandle(hInternet);\r\n        return -2;\r\n    }\r\n\r\n    DWORD dwSize;\r\n    DWORD dwRead, dwWritten, dwTotalSize;\r\n    DWORD dwCursor = 0;\r\n\r\n    bool bOK = HttpQueryInfo(hURL, HTTP_QUERY_CONTENT_LENGTH, pBuffer, \r\n        &dwRead, NULL);\r\n    if(!bOK) return -4;\r\n    dwTotalSize = atoi((const char *)pBuffer);\r\n\r\n    do {\r\n        InternetQueryDataAvailable(hURL, &dwSize, 0, 0);\r\n        InternetReadFile(hURL, (LPVOID)(pBuffer + dwCursor), dwSize, &dwRead);\r\n        dwCursor += dwRead;\r\n    } while(dwRead != 0);\r\n\r\n    InternetCloseHandle(hURL);\r\n\r\n    return dwTotalSize;\r\n}<\/pre>\n<p> \ub05d\uc73c\ub85c \uc774 \ud568\uc218 \uc0ac\uc6a9\uc744 \uc704\ud574 \ud5e4\ub354 \ud30c\uc77c\ub85c wininet.h\uc640 \ub77c\uc774\ube0c\ub7ec\ub9ac \ud30c\uc77c\ub85c wininet.lib\uac00 \ud544\uc694\ud569\ub2c8\ub2e4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\uc608\uc804\uc5d0 \ub9cc\ub4e4\uc5b4 \ub193\uc740 \uac83\uc774 \uc788\ub294\ub370.. \ub3c4\ud1b5 \ucc3e\uc744 \uc218\uac00 \uc5c6\uc5b4\uc11c \ub2e4\uc2dc \ub9cc\ub4e4\uc5b4 \ubcf8 \ud568\uc218\uc785\ub2c8\ub2e4. URL \uacbd\ub85c\uc5d0 \uc874\uc7ac\ud558\ub294 \ub370\uc774\ud130\ub97c \ub2e4\uc6b4\ub85c\ub4dc\ud558\uc5ec \ub85c\uceec \ud30c\uc77c\ub85c \uc800\uc7a5\ud574 \uc8fc\ub294 \ud568\uc218\uc785\ub2c8\ub2e4. \uc2e4\uc81c \uac1c\ubc1c\uc5d0 \uc0ac\uc6a9\ud560 \uc694\ub7c9\uc73c\ub85c \uc778\uc790\uac00 \uc81c\ubc95 \ubcf5\uc7a1\ud569\ub2c8\ub2e4. DWORD Download(HINTERNET hInternet, char *pszURL, char *pszFileName, BYTE *pBuffer) { HINTERNET hURL = InternetOpenUrl(hInternet, pszURL, NULL, 0, 0, 0); if(hURL == NULL) { InternetCloseHandle(hInternet); return &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=1838\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;[C++] URL\ub85c\ubd80\ud130 \ubc14\uc774\ub108\ub9ac \ub370\uc774\ud130 \ub2e4\uc6b4\ub85c\ub4dc&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[117,8],"tags":[],"class_list":["post-1838","post","type-post","status-publish","format-standard","hentry","category-cpp","category-programming"],"_links":{"self":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/1838","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1838"}],"version-history":[{"count":1,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/1838\/revisions"}],"predecessor-version":[{"id":2982,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/1838\/revisions\/2982"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1838"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1838"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1838"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}