/* * Time-stamp: <2002-08-28 18:03:59 takeuchi> * Ver 1.0 by Yuji Takeuchi * w3.C * This file contains two fuctions: wget and wpost. * The function wget can fetch a web page via GET method in http protocol, * while the function wpost can post data to a web page via POST method. * * usage: * .L w3.C or #include "w3.C" * * TString page; * wget(page, "hostname", "/html/index.html", 80); * // this is equivalent to 'http://hogename:80/html/index.html' */ Bool_t wget(TString& page, const char* host, const char* dir, Int_t port) { // Socket open TSocket* socket = new TSocket(host, port); if (! socket->IsValid()) return kFALSE; // set GET request socket->SendRaw("GET ", 4); socket->SendRaw(dir, strlen(dir)); socket->SendRaw(" HTTP/1.0\n\n", 11); // get Result from server char recvBuff; while (socket->RecvRaw(&recvBuff, 1)) { // cout << nbyte << " " << socket->GetBytesRecv() << endl; page.Append(recvBuff); } // Socket close socket->Close(); // separate header from page content Ssiz_t idx=page.Index("\n\r\n"); TString header=page(0, idx+1); page.Remove(0,idx+3); idx=header.Index(" "); TString status=header(idx+1, 3); if (status == "200" ) return kTRUE; return kFALSE; } /* * wpost */ Bool_t wpost(TString& page, Int_t nkey, TString* keys, TString* values, const char* host, const char* dir, Int_t port) { // make boundary static const TString CRCF("\r\n"); static const TString SS("--"); TString boundary("13498930121748110840348153983"); // set multi part TString mpart; for(Int_t idx=0; idxIsValid()) return kFALSE; //cout << request << endl; socket->SendRaw(request.Data(), request.Length()); // get Result from server char recvBuff; while (socket->RecvRaw(&recvBuff, 1)) { // cout << nbyte << " " << socket->GetBytesRecv() << endl; page.Append(recvBuff); } // Socket close socket->Close(); // separate header from page content Ssiz_t idx=page.Index("\n\r\n"); TString header=page(0, idx+1); page.Remove(0,idx+3); idx=header.Index(" "); TString status=header(idx+1, 3); if (status == "200" ) return kTRUE; return kFALSE; }