PDA

Просмотр полной версии : Простой HTTP запрос через WinAPI и обработка JSON


g305noobo
23.09.2023, 12:30
для себя сделал, мб кому-то понадобится 🤔

C++:





[CODE]
#include
#include
#include
#include "nlohmann/json.hpp"
int
main
(
)
{
std
::
cout

0
)
{
response_data
.
append
(
buffer
,
bytesRead
)
;
}
std
::
cout

Digger Man52
23.09.2023, 12:54
Такое уж лучше в классе делать….

C++:






class
WebClient
{
private
:
HINTERNET hInternet
;
HINTERNET hConnect
;
public
:
bool
initialize
(
)
{
std
::
cout

0
)
{
response_data
.
append
(
buffer
,
bytesRead
)
;
}
std
::
cout



C++:





[CODE]
int
main
(
)
{
WebClient client
;
if
(
!
client
.
initialize
(
)
)
{
return
1
;
}
if
(
!
client
.
openUrl
(
L
"ссылка"
)
)
{
return
1
;
}
std
::
string response_data
=
client
.
readResponse
(
)
;
nlohmann
::
json json_response
;
if
(
!
client
.
parseJson
(
response_data
,
json_response
)
)
{
return
1
;
}
// жсон
return
0
;
}