Пример #1
0
int get_file( const char* path )
{
    log_msg("\nget_file()\n    path=%s\n",path);
    //Service CService;
    //string url = "http://10.211.55.8/getdata.php?key=ss";
    vector<string> customheader;
    CService.clean();
    int nres =  CService.HttpRequest("GET", path ,NULL,customheader,&CService);
    //int nres =  CService.HttpRequest("GET", url.c_str(),NULL,customheader,&CService);
   if(nres == CURLE_OK)
   {
       log_msg("download buf=%s\n",CService.m_resp_buffer.c_str());
       return CURLE_OK;
   }
   return -1;
}
Пример #2
0
int post_file( const char* path )
{
    string postFileData;
    string strBoundary = "----WebKitFormBoundaryx386qjAs2dAgshUG";
    string formMultipart = "Content-Type: multipart/form-data; boundary=" + strBoundary;
    vector<string> custom_headers;
    custom_headers.push_back( formMultipart );
    postFileData = postFileData + "--" + strBoundary + "\r\n";
    postFileData += "Content-Disposition: form-data; name=\"file\"; filename=\"10K.txt\"\r\n";
    postFileData += "Content-Type: text/plain\r\n";
    postFileData += "\r\n";

    unsigned char* buf = NULL;
    int nLen = -1;
    int nres = -1;
    nres = get_file_content( path, &buf, &nLen );
    log_msg("post_file: get_file_content nres=%d\n",nres);
    if ( nLen > 0 ) {
       postFileData.append( (char*)buf, nLen ); 
    }
    else 
    {
        nLen = strlen(path+1);
        postFileData.append( path+1, nLen );
    }

    postFileData += "\r\n";

    postFileData = postFileData + "--" + strBoundary + "--\r\n";

    HTTPDATA postFormData;
    memset( &postFormData, 0, sizeof(postFormData) );
    postFormData.data = (char*)postFileData.data();
    postFormData.datalen = postFileData.size();
    postFormData.totallen = postFileData.size();


    CService.clean();
    nres = CService.HttpRequest( "POST", BB_DATA->httpposturl, &postFormData,custom_headers,&CService);
    log_msg("\npost_file()\n    respbuf=%s\n",CService.m_resp_buffer.c_str());
    if ( nres ==0 && nLen>0 ) {
        return nLen;
    }
    return 0;
}