Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Системное программирование и WinAPI > problem using HttpOpenRequest(...),HttpSendRequest


Автор: BlackCode 8.5.2005, 15:37
Hello people.

Those who ever worked with the Internet***** APIs, please help, I need some working examples.

This code is working fine, but

Код

#include <windows.h>
#include <wininet.h>

#include <iostream>

using std::cout;

void main()
{
    auto HINTERNET hOpen = InternetOpen(
      "MyAgent",
      INTERNET_OPEN_TYPE_DIRECT,
      NULL,
      NULL,
      0);
    cout<<"hOpen="<<(INT)hOpen<<"\nGetLastError()="<<GetLastError()<<"\n\n\n";

    auto HINTERNET hUrl = InternetOpenUrl(
      hOpen,
      "http://www.freenet.am",
      0,0,
      INTERNET_FLAG_RELOAD | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_NO_COOKIES,
      0);
    cout<<"hUrl="<<(INT)hUrl<<"\nGetLastError()="<<GetLastError()<<"\n\n\n";

    auto char  buffer[128];
    auto DWORD uLong;

    while(1){

  if(InternetReadFile(hUrl,buffer,128,&uLong) == FALSE){
    MessageBox(0,"ERROR InternetReadFile returns NULL","ERROR",0);
            break;
  }
    
  for(UINT i=0;i<128;i++){
            cout<<buffer[i];
  }

  if(uLong < 128){
            break;
  }

  InternetSetFilePointer(hUrl,128,0,FILE_CURRENT,0);
    }

    Sleep(10000);

    cout<<"\n\n\nGetLastError()="<<GetLastError()<<"\n";
    InternetCloseHandle(hUrl);
    InternetCloseHandle(hOpen);
    cout<<"\n\n\nGetLastError()="<<GetLastError()<<"\n";
}


but when I try to use the
InternetConnect(...),
HttpOpenRequest(...),
HttpSendRequest(...)

instead of InternetOpenUrl(...)
it fails when calling HttpSendRequest(...) smile
it sends packets to the server and then fails.
GetLastError() returns 12007 error code,
which is not documented in the Platform SDK 2003 error codes.

look down for the details

Код

#include <windows.h>
#include <wininet.h>

#include <iostream>

using std::cout;

void main()
{
    auto HINTERNET hOpen = InternetOpen(
      "MyAgent",
      INTERNET_OPEN_TYPE_DIRECT,
      NULL,
      NULL,
      0);
    cout<<"hOpen="<<(INT)hOpen<<"\nGetLastError()="<<GetLastError()<<"\n\n\n";

    auto HINTERNET hConnect = InternetConnect(
      hOpen,
      "http://www.freenet.am",
      80,
      NULL,
      NULL,
      INTERNET_SERVICE_HTTP,
      0,0);
    cout<<"hConnect="<<(INT)hConnect<<"\nGetLastError()="<<GetLastError()<<"\n\n\n";

    auto HINTERNET hRequest = HttpOpenRequest(
      hConnect,
      "GET",
      "index.html",
      0,
      "http://forum.vision.am",
      (LPCSTR *)"",
      INTERNET_FLAG_NO_AUTH | INTERNET_FLAG_RELOAD | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_NO_COOKIES | INTERNET_FLAG_NO_CACHE_WRITE,
      0);
    cout<<"hRequest="<<(INT)hRequest<<"\nGetLastError()="<<GetLastError()<<"\n\n\n";

    auto BOOL sendRes = HttpSendRequest(
      hRequest,
      0,0,
      0,0);
    cout<<"sendRes="<<(INT)sendRes<<"\nGetLastError()="<<GetLastError()<<"\n\n\n";
}



The console output
Код

hOpen=13369348
GetLastError()=0


hConnect=13369352
GetLastError()=0


hRequest=13369356
GetLastError()=0


sendRes=0
GetLastError()=12007


Press any key to continue


Regards, Aram

Автор: SeregaLBN 12.5.2005, 17:57
Как это не определена ошибка. Ошибаешся...

файл WinInet.h

//
// Internet API error returns
//

#define INTERNET_ERROR_BASE 12000

#define ERROR_INTERNET_NAME_NOT_RESOLVED (INTERNET_ERROR_BASE + 7)

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)