├── .gitignore
├── ReadMe.txt
├── WinHttpExample.cpp
├── WinHttpExample.sln
├── WinHttpExample.vcxproj
├── WinHttpExample.vcxproj.filters
├── stdafx.cpp
├── stdafx.h
└── targetver.h
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.sln.docstates
8 |
9 | # Build results
10 |
11 | [Dd]ebug/
12 | [Rr]elease/
13 | x64/
14 | build/
15 | [Bb]in/
16 | [Oo]bj/
17 | *.exe
18 | *.o
19 | *.res
20 |
21 | # MSTest test Results
22 | [Tt]est[Rr]esult*/
23 | [Bb]uild[Ll]og.*
24 |
25 | *_i.c
26 | *_p.c
27 | *.ilk
28 | *.meta
29 | *.obj
30 | *.pch
31 | *.pdb
32 | *.pgc
33 | *.pgd
34 | *.rsp
35 | *.sbr
36 | *.tlb
37 | *.tli
38 | *.tlh
39 | *.tmp
40 | *.tmp_proj
41 | *.log
42 | *.vspscc
43 | *.vssscc
44 | .builds
45 | *.pidb
46 | *.log
47 | *.scc
48 |
49 | # Visual C++ cache files
50 | ipch/
51 | *.aps
52 | *.ncb
53 | *.opensdf
54 | *.sdf
55 | *.cachefile
56 |
57 | # Visual Studio profiler
58 | *.psess
59 | *.vsp
60 | *.vspx
61 |
62 | # Guidance Automation Toolkit
63 | *.gpState
64 |
65 | # ReSharper is a .NET coding add-in
66 | _ReSharper*/
67 | *.[Rr]e[Ss]harper
68 |
69 | # TeamCity is a build add-in
70 | _TeamCity*
71 |
72 | # DotCover is a Code Coverage Tool
73 | *.dotCover
74 |
75 | # NCrunch
76 | *.ncrunch*
77 | .*crunch*.local.xml
78 |
79 | # Installshield output folder
80 | [Ee]xpress/
81 |
82 | # DocProject is a documentation generator add-in
83 | DocProject/buildhelp/
84 | DocProject/Help/*.HxT
85 | DocProject/Help/*.HxC
86 | DocProject/Help/*.hhc
87 | DocProject/Help/*.hhk
88 | DocProject/Help/*.hhp
89 | DocProject/Help/Html2
90 | DocProject/Help/html
91 |
92 | # Click-Once directory
93 | publish/
94 |
95 | # Publish Web Output
96 | *.Publish.xml
97 | *.pubxml
98 |
99 | # NuGet Packages Directory
100 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
101 | #packages/
102 |
103 | # Windows Azure Build Output
104 | csx
105 | *.build.csdef
106 |
107 | # Windows Store app package directory
108 | AppPackages/
109 |
110 | # Others
111 | sql/
112 | *.Cache
113 | ClientBin/
114 | [Ss]tyle[Cc]op.*
115 | ~$*
116 | *~
117 | *.dbmdl
118 | *.[Pp]ublish.xml
119 | *.pfx
120 | *.publishsettings
121 |
122 | # RIA/Silverlight projects
123 | Generated_Code/
124 |
125 | # Backup & report files from converting an old project file to a newer
126 | # Visual Studio version. Backup files are not needed, because we have git ;-)
127 | _UpgradeReport_Files/
128 | Backup*/
129 | UpgradeLog*.XML
130 | UpgradeLog*.htm
131 |
132 | # SQL Server files
133 | App_Data/*.mdf
134 | App_Data/*.ldf
135 |
136 | # =========================
137 | # Windows detritus
138 | # =========================
139 |
140 | # Windows image file caches
141 | Thumbs.db
142 | ehthumbs.db
143 |
144 | # Folder config file
145 | Desktop.ini
146 |
147 | # Recycle Bin used on file shares
148 | $RECYCLE.BIN/
149 |
150 | # Mac crap
151 | .DS_Store
152 | *.stackdump
153 |
154 | # etags
155 | TAGS
156 |
157 | # emacs crap
158 | \#*\#
159 |
--------------------------------------------------------------------------------
/ReadMe.txt:
--------------------------------------------------------------------------------
1 | ========================================================================
2 | CONSOLE APPLICATION : WinHttpExample Project Overview
3 | ========================================================================
4 |
5 | AppWizard has created this WinHttpExample application for you.
6 |
7 | This file contains a summary of what you will find in each of the files that
8 | make up your WinHttpExample application.
9 |
10 |
11 | WinHttpExample.vcxproj
12 | This is the main project file for VC++ projects generated using an Application Wizard.
13 | It contains information about the version of Visual C++ that generated the file, and
14 | information about the platforms, configurations, and project features selected with the
15 | Application Wizard.
16 |
17 | WinHttpExample.vcxproj.filters
18 | This is the filters file for VC++ projects generated using an Application Wizard.
19 | It contains information about the association between the files in your project
20 | and the filters. This association is used in the IDE to show grouping of files with
21 | similar extensions under a specific node (for e.g. ".cpp" files are associated with the
22 | "Source Files" filter).
23 |
24 | WinHttpExample.cpp
25 | This is the main application source file.
26 |
27 | /////////////////////////////////////////////////////////////////////////////
28 | Other standard files:
29 |
30 | StdAfx.h, StdAfx.cpp
31 | These files are used to build a precompiled header (PCH) file
32 | named WinHttpExample.pch and a precompiled types file named StdAfx.obj.
33 |
34 | /////////////////////////////////////////////////////////////////////////////
35 | Other notes:
36 |
37 | AppWizard uses "TODO:" comments to indicate parts of the source code you
38 | should add to or customize.
39 |
40 | /////////////////////////////////////////////////////////////////////////////
41 |
--------------------------------------------------------------------------------
/WinHttpExample.cpp:
--------------------------------------------------------------------------------
1 | // WinHttpExample.cpp : Defines the entry point for the console application.
2 | //
3 |
4 | #include "stdafx.h"
5 | #include "windows.h"
6 | #include "winhttp.h"
7 |
8 | int _tmain(int argc, _TCHAR* argv[])
9 | {
10 | // WinHTTP Sessions Overview | https://msdn.microsoft.com/en-us/library/windows/desktop/aa384270(v=vs.85).aspx
11 |
12 | DWORD dwSize = 0;
13 | DWORD dwDownloaded = 0;
14 | LPSTR pszOutBuffer;
15 | BOOL bResults = FALSE;
16 | HINTERNET hSession = NULL,
17 | hConnect = NULL,
18 | hRequest = NULL;
19 |
20 | // Use WinHttpOpen to obtain a session handle.
21 | hSession = WinHttpOpen(L"WinHTTP Example/1.0",
22 | WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
23 | WINHTTP_NO_PROXY_NAME,
24 | WINHTTP_NO_PROXY_BYPASS, 0);
25 |
26 | // Specify an HTTP server.
27 | if (hSession)
28 | hConnect = WinHttpConnect(hSession, L"www.microsoft.com",
29 | INTERNET_DEFAULT_HTTPS_PORT, 0);
30 |
31 | // Create an HTTP request handle.
32 | if (hConnect)
33 | hRequest = WinHttpOpenRequest(hConnect, L"GET", NULL,
34 | NULL, WINHTTP_NO_REFERER,
35 | WINHTTP_DEFAULT_ACCEPT_TYPES,
36 | WINHTTP_FLAG_SECURE);
37 |
38 | // Send a request.
39 | if (hRequest)
40 | bResults = WinHttpSendRequest(hRequest,
41 | WINHTTP_NO_ADDITIONAL_HEADERS, 0,
42 | WINHTTP_NO_REQUEST_DATA, 0,
43 | 0, 0);
44 |
45 |
46 | // End the request.
47 | if (bResults)
48 | bResults = WinHttpReceiveResponse(hRequest, NULL);
49 |
50 | // Keep checking for data until there is nothing left.
51 | if (bResults)
52 | {
53 | do
54 | {
55 | // Check for available data.
56 | dwSize = 0;
57 | if (!WinHttpQueryDataAvailable(hRequest, &dwSize))
58 | printf("Error %u in WinHttpQueryDataAvailable.\n",
59 | GetLastError());
60 |
61 | // Allocate space for the buffer.
62 | pszOutBuffer = new char[dwSize + 1];
63 | if (!pszOutBuffer)
64 | {
65 | printf("Out of memory\n");
66 | dwSize = 0;
67 | }
68 | else
69 | {
70 | // Read the data.
71 | ZeroMemory(pszOutBuffer, dwSize + 1);
72 |
73 | if (!WinHttpReadData(hRequest, (LPVOID)pszOutBuffer,
74 | dwSize, &dwDownloaded))
75 | printf("Error %u in WinHttpReadData.\n", GetLastError());
76 | else
77 | printf("%s", pszOutBuffer);
78 |
79 | // Free the memory allocated to the buffer.
80 | delete[] pszOutBuffer;
81 | }
82 | } while (dwSize > 0);
83 | }
84 |
85 |
86 | // Report any errors.
87 | if (!bResults)
88 | printf("Error %d has occurred.\n", GetLastError());
89 |
90 | // Close any open handles.
91 | if (hRequest) WinHttpCloseHandle(hRequest);
92 | if (hConnect) WinHttpCloseHandle(hConnect);
93 | if (hSession) WinHttpCloseHandle(hSession);
94 |
95 | return 0;
96 | }
97 |
98 |
--------------------------------------------------------------------------------
/WinHttpExample.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Express 2013 for Windows Desktop
4 | VisualStudioVersion = 12.0.40629.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinHttpExample", "WinHttpExample.vcxproj", "{6D61F1F5-8589-4AFB-9CA3-8A17B54CB96C}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Win32 = Debug|Win32
11 | Release|Win32 = Release|Win32
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {6D61F1F5-8589-4AFB-9CA3-8A17B54CB96C}.Debug|Win32.ActiveCfg = Debug|Win32
15 | {6D61F1F5-8589-4AFB-9CA3-8A17B54CB96C}.Debug|Win32.Build.0 = Debug|Win32
16 | {6D61F1F5-8589-4AFB-9CA3-8A17B54CB96C}.Release|Win32.ActiveCfg = Release|Win32
17 | {6D61F1F5-8589-4AFB-9CA3-8A17B54CB96C}.Release|Win32.Build.0 = Release|Win32
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/WinHttpExample.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {6D61F1F5-8589-4AFB-9CA3-8A17B54CB96C}
15 | Win32Proj
16 | WinHttpExample
17 |
18 |
19 |
20 | Application
21 | true
22 | v120
23 | Unicode
24 |
25 |
26 | Application
27 | false
28 | v120
29 | true
30 | Unicode
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | true
44 |
45 |
46 | false
47 |
48 |
49 |
50 |
51 |
52 | Level3
53 | Disabled
54 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
55 |
56 |
57 | Console
58 | true
59 | winhttp.lib;%(AdditionalDependencies)
60 |
61 |
62 |
63 |
64 | Level3
65 |
66 |
67 | MaxSpeed
68 | true
69 | true
70 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
71 |
72 |
73 | Console
74 | true
75 | true
76 | true
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/WinHttpExample.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 |
29 |
30 | Header Files
31 |
32 |
33 | Header Files
34 |
35 |
36 |
--------------------------------------------------------------------------------
/stdafx.cpp:
--------------------------------------------------------------------------------
1 | // stdafx.cpp : source file that includes just the standard includes
2 | // WinHttpExample.pch will be the pre-compiled header
3 | // stdafx.obj will contain the pre-compiled type information
4 |
5 | #include "stdafx.h"
6 |
7 | // TODO: reference any additional headers you need in STDAFX.H
8 | // and not in this file
9 |
--------------------------------------------------------------------------------
/stdafx.h:
--------------------------------------------------------------------------------
1 | // stdafx.h : include file for standard system include files,
2 | // or project specific include files that are used frequently, but
3 | // are changed infrequently
4 | //
5 |
6 | #pragma once
7 |
8 | #include "targetver.h"
9 |
10 | #include
11 | #include
12 |
13 |
14 |
15 | // TODO: reference additional headers your program requires here
16 |
--------------------------------------------------------------------------------
/targetver.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | // Including SDKDDKVer.h defines the highest available Windows platform.
4 |
5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
7 |
8 | #include
9 |
--------------------------------------------------------------------------------