invoke http within VC++

  • Thread starter Thread starter Rudy Ko
  • Start date Start date
R

Rudy Ko

Hi, all,

Anyone know how to issue a http request from VC or have a sample?
Thanks!!

Regards,
Rudy
 
Hi Rudy Ko,
Anyone know how to issue a http request from VC or have a sample?

MFC: CHttpConnection Class
http://msdn.microsoft.com/library/en-us/vclib/html/_MFC_CHttpConnection.asp

WinInet: Using WinInet HTTP functions in Full Asynchronous Mode
http://www.codeproject.com/internet/asyncwininet.asp

WinInet: Simple HTTP Client using WININET
http://www.codeproject.com/internet/simplehttpclient.asp

Or you can use the native socket functions....

See: Winsock 2
http://msdn.microsoft.com/library/en-
us/winsock/winsock/windows_sockets_start_page_2.asp

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
Jochen said:
Hi Rudy Ko,


MFC: CHttpConnection Class
http://msdn.microsoft.com/library/en-us/vclib/html/_MFC_CHttpConnection.asp

WinInet: Using WinInet HTTP functions in Full Asynchronous Mode
http://www.codeproject.com/internet/asyncwininet.asp

WinInet: Simple HTTP Client using WININET
http://www.codeproject.com/internet/simplehttpclient.asp

Or you can use the native socket functions....

See: Winsock 2
http://msdn.microsoft.com/library/en-
us/winsock/winsock/windows_sockets_start_page_2.asp

Or you can use WinHttp:

http://msdn.microsoft.com/library/d.../winhttp/http/using_the_winhttp_c_c___api.asp

Or you can use the URLMON library.

See

http://msdn.microsoft.com/library/default.asp?url=/workshop/networking/moniker/overview/overview.asp

Note: URL monikers are only usfulo for issuing a GET request. If you need
to do a POST or HEAD or anything else, you can't use URL monikers.

Below is a complete program to fetch and save a file from HTTP

-cd

#include <windows.h>
#include <tchar.h>
#include <urlmon.h>
#include <stdio.h>

int _tmain(int argc, TCHAR* argv[])
{

if (3 != argc)
{
_tprintf(_T("usage: %0 URL out-file-name"),argv[0]);
return 1;
}

::CoInitialize(0);
TCHAR szFullName[MAX_PATH];
::GetFullPathName(argv[2],MAX_PATH,szFullName,0);
HRESULT hr = ::URLDownloadToFile(
0,
argv[1],
szFullName,
0,
0
);
::CoUninitialize();

if (FAILED(hr))
{
_tprintf(_T("Failed, hr=0x%08x\n"),hr);
return 2;
}

return 0;
}
 
Actually you can use URL monikers for performing POST and HEAD requests.

See RegisterBindStatusCallback.

It's not simple, but it's certainly doable.


Jochen said:
Hi Rudy Ko,



MFC: CHttpConnection Class
http://msdn.microsoft.com/library/en-us/vclib/html/_MFC_CHttpConnection.asp

WinInet: Using WinInet HTTP functions in Full Asynchronous Mode
http://www.codeproject.com/internet/asyncwininet.asp

WinInet: Simple HTTP Client using WININET
http://www.codeproject.com/internet/simplehttpclient.asp

Or you can use the native socket functions....

See: Winsock 2
http://msdn.microsoft.com/library/en-
us/winsock/winsock/windows_sockets_start_page_2.asp


Or you can use WinHttp:

http://msdn.microsoft.com/library/d.../winhttp/http/using_the_winhttp_c_c___api.asp

Or you can use the URLMON library.

See

http://msdn.microsoft.com/library/default.asp?url=/workshop/networking/moniker/overview/overview.asp

Note: URL monikers are only usfulo for issuing a GET request. If you need
to do a POST or HEAD or anything else, you can't use URL monikers.

Below is a complete program to fetch and save a file from HTTP

-cd

#include <windows.h>
#include <tchar.h>
#include <urlmon.h>
#include <stdio.h>

int _tmain(int argc, TCHAR* argv[])
{

if (3 != argc)
{
_tprintf(_T("usage: %0 URL out-file-name"),argv[0]);
return 1;
}

::CoInitialize(0);
TCHAR szFullName[MAX_PATH];
::GetFullPathName(argv[2],MAX_PATH,szFullName,0);
HRESULT hr = ::URLDownloadToFile(
0,
argv[1],
szFullName,
0,
0
);
::CoUninitialize();

if (FAILED(hr))
{
_tprintf(_T("Failed, hr=0x%08x\n"),hr);
return 2;
}

return 0;
}
 
Back
Top