okutil_http_download

 

Description

Download from given URL to a file, with https(SSL) support

Syntax

int okutil_http_download( LPCSTR lpcszURL, LPCSTR lpcszFileName, int nConnectTimeout = 0, int nResponseTimeout = 0, BOOL bIgnoreCertError = FALSE )

Parameters

lpcszURL
[input]The URL specify the target file to download
lpcszFileName
[input]The local file to receive data downloaded from lpcszURL
nConnectionTimeout
[input]The number of seconds to specify timeout limit when connect to server
nResponseTimeout
[input]The number of seconds to specify timeout limit waiting for response of a request
bIgnoreCertError
[input]Ignore Error

Return

Return OHTTP_E_OK for success, other negative values are error code.

Examples

//assume active book empty
void stock()
{
        string strSymbol = "MSFT";//you need apikey if searching any other stock
        string strFile = GetOriginPath(ORIGIN_PATH_USER) + strSymbol + "_stock.csv";
        string strURL = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=";
        strURL += strSymbol;
        strURL += "&apikey=demo&datatype=csv";
        string result;
        int err = okutil_http_download(strURL, strFile);
        if( err != 0 ) {
                out_int("err = ", err);
                return;
        }
        Worksheet wks = Project.ActiveLayer();
        ASCIMP  ai;
        if(AscImpReadFileStruct(strFile, &ai)==0) {
                ai.iSubHeaderLines = 1;
                ai.nLongNames = 1;
                wks.ImportASCII(strFile, ai);
                Column col(wks, 0);
                col.SetFormat(OKCOLTYPE_DATE, "yyyy'-'MM'-'dd");
        }
}

Remark

See Also

Header to Included

origin.h

Reference