| |

VerySource

 Forgot password?
 Register
Search
View: 539|Reply: 1

How to send GET method using httpOpenRequest

[Copy link]

3

Threads

10

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-1-26 14:00:01
| Show all posts |Read mode
hRequest = HttpOpenRequest (
hConnect,
TEXT ("GET"),
NULL,
TEXT ("HTTP / 1.1"),
NULL,
(LPCTSTR *) AcceptTypes,
dwFlags, 0
);
if (! hRequest)
goto end;

if (! HttpSendRequest (hRequest, data, datalen, NULL, 0))
goto end;

Is this code correct ...
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-6-15 12:30:01
| Show all posts
You will know it if you try it. . .

HINTERNET hSession = ::InternetOpen("MSDN SurfBear",
PRE_CONFIG_INTERNET_ACCESS,
NULL,
INTERNET_INVALID_PORT_NUMBER,
0);
The
// Connect to www.microsoft.com.
HINTERNET hConnect = ::InternetConnect(hSession,
"news.163.com",
INTERNET_INVALID_PORT_NUMBER,
"",
"",
INTERNET_SERVICE_HTTP,
0,
0);
The
// Request the file /MSDN/MSDNINFO/ from the server.
HINTERNET hHttpFile = ::HttpOpenRequest(hConnect,
"GET",
"/domestic",
HTTP_VERSION,
NULL,
0,
INTERNET_FLAG_DONT_CACHE,
                1);
The
// Send the request.
BOOL bSendRequest = ::HttpSendRequest(hHttpFile, NULL, 0, 0, 0);
The
// Get the length of the file.
char bufQuery[32];
DWORD dwLengthBufQuery = sizeof(bufQuery);
BOOL bQuery = ::HttpQueryInfo(hHttpFile, HTTP_QUERY_CONTENT_LENGTH, bufQuery,&dwLengthBufQuery, NULL);
The
// Convert length from ASCII string to a DWORD.
DWORD dwFileSize = (DWORD)atol(bufQuery);
The
// Allocate a buffer for the file.
char* buffer = new char[dwFileSize+1];
The
// Read the file into the buffer.
DWORD dwBytesRead;
BOOL bRead = ::InternetReadFile(hHttpFile,
buffer,
dwFileSize+1,
&dwBytesRead);
// Put a zero on the end of the buffer.
AfxMessageBox(buffer);
buffer[dwBytesRead] = 0;
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list