W3 Client

UploadedFilesVELOCE RCVitoAudioNotesVoteVoteMacro W3Client


W3Client

usage

Synchronized HTTP GET

#include <iostream>
#include "w3c.h"

using namespace std;

int main(int argc, char *argv[]){
  
  W3Client w3;
 
  if(w3.Connect("http://google.com/")){
   if(w3.Request("/")){
    char buf[1024]="\0";
    while(w3.Response(reinterpret_cast<unsigned char *>(buf), 1024))
     cout << buf ;
  }
   w3.Close();
  }
  return 0;
}


Synchronized HTTP POST multiparts/form-data

int main(int argc, char *argv[]){
 
 W3Client client;

 if(client.Connect("http://gooshin.zzem.net/")){
  client.AddPostArgument("f[]", "d:\\log1.txt", true);
  client.AddPostArgument("f[]", "d:\\log2.txt", true);
  client.AddPostArgument("f[]", "d:\\log3.txt", true);
  if(client.Request("/test.php", W3Client::reqPostMultipartsFormdata)){
   char buf[1024]="\0";
   while(client.Response(reinterpret_cast<unsigned char*>(buf), 1024)>0){
    cout << buf << endl;
    memset(buf, 0x00, 1024);
   }
  }
  client.Close();
 }

 return 0;
}

Asynchronized HTTP client

#include <iostream>
#include <net/w3c.h>
#include <wt.h>
#include <windows.h>

using namespace std;

CRITICAL_SECTION __cs;

class AsDown : public AsyncW3Client, public IWORKERTHREAD {
public:
 AsDown(unsigned int idx):AsyncW3Client(), IWORKERTHREAD(idx){}
 virtual ~AsDown(){}
private:
 virtual void OnWork(){
  while(true){
   WaitCompleteRequest();
   unsigned char buf[1024]="\0";
   while(Response(buf, 1024)){
     ::EnterCriticalSection(&__cs);
     cout << reinterpret_cast<char*>(buf);
     ::LeaveCriticalSection(&__cs);
     memset(buf, 0x00, 1024);
   }
   ::Sleep(500);
  }
 }
};
void CALLBACK __getstatus(  HINTERNET hInternet,
               DWORD_PTR dwContext,
               DWORD dwInternetStatus,
               LPVOID lpvStatusInformation,
               DWORD dwStatusInformationLength
               ){
 AsyncW3Client *pcontext=reinterpret_cast<AsyncW3Client*>(dwContext);
 
 unsigned long nbytes=0;
  ::EnterCriticalSection(&__cs);
  switch(dwInternetStatus){
 case INTERNET_STATUS_SENDING_REQUEST:
  cout << "request sending..." << endl;
  break;
 case INTERNET_STATUS_REQUEST_SENT:
  {
   unsigned long *pnsent=(unsigned long*)lpvStatusInformation;
   cout << "bytes sent: " << *pnsent << endl;
   nbytes+=*pnsent;
   cout << "request sent..." << endl;
  }
  break;
 case INTERNET_STATUS_REQUEST_COMPLETE:
  {
   INTERNET_ASYNC_RESULT *pAsyncRes = 
          (INTERNET_ASYNC_RESULT *)lpvStatusInformation;
   cout << "Function call finished" << endl;
   cout << "dwResult: " << pAsyncRes->dwResult << endl;
   cout << "dwError:  " << pAsyncRes->dwError << endl;
   cout.flush();
   pcontext->SetCompleteRequest();
    cout << "request complete..." << endl;  
  }
  break;
  }
  ::LeaveCriticalSection(&__cs);
 
  return;
}
int main(int argc, char *argv[]){ 
 ::InitializeCriticalSection(&__cs);
 AsDown client(3);
 if(client.Connect("http://gooshin.zzem.net/", __getstatus)){
  __wtstart(client);
  client.Request("/test.php");
  Sleep(5000);
  client.InitializePostArguments();
  client.AddPostArgument("f[]", "d:\\log1.txt", true);
  client.AddPostArgument("f[]", "d:\\log2.txt", true);
  client.AddPostArgument("f[]", "d:\\log3.txt", true);
  client.Request("/test.php", AsDown::reqPostMultipartsFormdata);
  Sleep(5000);
  client.InitializePostArguments();
  client.AddPostArgument("f", "sss");
  client.Request("/test2.php", AsDown::reqPost);  
  Sleep(5000);
  
  __wtwait(client);
  client.Close();
 }
 ::DeleteCriticalSection(&__cs);
 return 0;
}


ID
Password
Join





- 전 이런 놈입니다.

격언> 쓰러질지언정 무릎은 꿇지 않는다. (박지성)

Recent Changes

D  Echoes Of War(The... @ 2012-05-18 [03:44 pm] by windlesszone
D  Diablo3 @ 2012-05-15 [04:49 pm] by windlesszone
D  Diablo3/story/wizard @ 2012-05-15 [04:48 pm] by windlesszone 4 changes
D  Diablo3/story/wit... @ 2012-05-15 [04:16 pm] by windlesszone
D  Diablo3/story/monk @ 2012-05-15 [04:14 pm] by windlesszone





Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2006-05-09 15:39:03
Processing time 0.0524 sec