Ir a contenido

PURCHASE MEMBERSHIP AT A 25% DISCOUNT Apply here

GET 1 MONTH OF MEMBERSHIP BY CHOOSING THE NEW NAME OF OUR COMPANY! Apply here


Photo

Leer una pagina web (Winhttp) C++


      
Leer una pagina web (Winhttp) C++ TvOTohoLeer una pagina web (Winhttp) C++ TvOToho
Leer una pagina web (Winhttp) C++

alexmen10
#1

alexmen10
  • alexmen10
  • administrator
  • Status :
    HS4L Team
  • Mensajes :
    418
  • Reputación :
    257
  • Points :
    23
  • Registrado :
    2012-09-08
Bueno estado investigando códigos "Microsoft" decidido formar mejor el código.Muchos piden un código para leer información del http
No publicare el proyecto motivo que uso Visual Studio 2015 (v140), pero vosotros podéis hacer un copia y pega. No hay problemas en las anteriores versiones. Aquí estarán las imágenes y los códigos.

[You must be registered and logged in to see this image.]

Code:
#include "stdafx.h"
#include <Windows.h>
#include <Winhttp.h>
#include <iostream>
#include <stdio.h>
#pragma comment(lib, "Winhttp.lib")
using namespace std;

int main()
{
//Variables
DWORD dwSize = 0;
DWORD dwDownloaded = 0;
LPSTR pszOutBuffer;
char textoweb[MAX_PATH];
HINTERNET
hSession = nullptr
, hConnect = nullptr
, hRequest = nullptr;

BOOL  bResults = FALSE;

// Usar WinHttpOpen para obtener acceso al handle.
 hSession = WinHttpOpen(L"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0",
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS, 0);
// Asignar al HTTP server
if (hSession)
hConnect = WinHttpConnect(hSession, L"raw.githubusercontent.com",
INTERNET_DEFAULT_HTTPS_PORT, 0);
// Crear un HTTP rquest handle
if (hConnect)
hRequest = WinHttpOpenRequest(hConnect, L"GET", L"/Tartian/test-wow/master/TEST.txt",
NULL, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
WINHTTP_FLAG_SECURE);


// enviar al  request.
if (hRequest)
bResults = WinHttpSendRequest(hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS,
0, WINHTTP_NO_REQUEST_DATA, 0,
0, 0);


// Poner fin al request
if (bResults)
bResults = WinHttpReceiveResponse(hRequest, NULL);

// Continuar para verificar datos
if (bResults)
do
{

// Verificar los datos
dwSize = 0;
if (!WinHttpQueryDataAvailable(hRequest, &dwSize))
printf("Error %u in WinHttpQueryDataAvailable.\n",
GetLastError());

// Asignar espacio para la memoria
pszOutBuffer = new char[dwSize + 1];
if (!pszOutBuffer)
{
printf("Out of memory\n");
dwSize = 0;
}
else
{
// Leer los datos.
ZeroMemory(pszOutBuffer, dwSize + 1);

if (!WinHttpReadData(hRequest, (LPVOID)pszOutBuffer,
dwSize, &dwDownloaded))
printf("Error %u in WinHttpReadData.\n", GetLastError());
else
printf("%s\n", pszOutBuffer);
sprintf_s(textoweb, "%s", pszOutBuffer);

// Liberar la memoria asignada a la memoria
delete[] pszOutBuffer;
}

} while (dwSize > 0);

// Informe de los errores.
if (!bResults)
printf("Error %d has occurred.\n", GetLastError());

// Close open handles.
if (hRequest) WinHttpCloseHandle(hRequest);
if (hConnect) WinHttpCloseHandle(hConnect);
if (hSession) WinHttpCloseHandle(hSession);

cout << textoweb; //muestra el texto de la web
system("pause");
return 0;
}

byalex123
#2

byalex123
  • byalex123
  • new member
  • Mensajes :
    3
  • Reputación :
    0
  • Points :
    0
  • Registrado :
    2015-11-13
smid_11
muy biena pagina
smid_1 lo recomendare

Seyer
#3

Seyer
  • Seyer
  • administrator
  • Status :
    HS4L Team
  • Mensajes :
    692
  • Reputación :
    64
  • Points :
    2
  • Registrado :
    2012-08-09
[You must be registered and logged in to see this link.]: inactividad del post.

Sponsored content
#4

Sponsored content

      

Create an account or log in to leave a reply

You need to be a member in order to leave a reply.

Create an account

Join our community by creating a new account. It's easy!


Create a new account

Log in

Already have an account? No problem, log in here.


Log in
You cannot reply to topics in this forum
Staff online
Sponsors
  •  TOTAL POSTS
  •  TOTAL MEMBERS
  •  NEWEST MEMBER