2.1.21.10 okutil_http_ex
Description
get data from a web service or POST request to server
Syntax
int okutil_http_ex( LPCSTR lpcszURL, OCHTTP_t * phttp )
Parameters
- lpcszURL
- [input] the web service URL
- phttp
- [input/output] HTTP setting
typedef struct {
DWORD dwOptions; // see OCHTTP_*
int nConnectTimeout; //the number of seconds an HTTP request has to establish a connection before it times out
int nResponseTimeout; //the number of seconds to wait for a response
BOOL bIgnoreCertError; //Ignore Error
LPCSTR pcszSrc; // request data
LPCSTR pcszDst; // file from service
LPVOID pstrDst; // string from service
LPCSTR pcszRequestHeader; //request header
LPVOID pstrResp; //result from the call
} OCHTTP_t;
enum {
OCHTTP_GET = 0x0001, //get data from service
OCHTTP_POST = 0x0002, //POST request to ser
OCHTTP_SRC_STR = 0x0010, //pcszSrc is request data
OCHTTP_SRC_FILE = 0x0020, //pcszSrc is full path name of the file with the request data
OCHTTP_DST_STR = 0x0040, //get string from service
OCHTTP_DST_FILE = 0x0080, //get file from service
OCHTTP_PROGRESSBAR = 0x0100, /// EJP 2019-01-23 ORG-19597-S4 OKUTIL_HTTP_PROGRESS_BAR
OCHTTP_SRC_BIN = 0x0200, /// EJP 2024-04-17 ORG-28773-S1 HTTP_POST_BINARY_FILE
};
Return
0 if succcess, otherwise an negative error code
Examples
EX1
void okutil_http_ex_download(LPCSTR lpcszURL, string&strResp, string&strTmpFileName)
{
// init http settings for download.
OCHTTP_t http;
http.dwOptions = OCHTTP_GET | OCHTTP_DST_FILE;
http.bIgnoreCertError = true;
http.nConnectTimeout = 0;
http.nResponseTimeout = 30;
http.pcszDst = strTmpFileName; // download to temp file.
http.pstrResp = &strResp;
int nErrr = okutil_http_ex(lpcszURL, &http);
printf("err %d\n", nErrr);
}
EX2
void test_http_post_text_file()
{
OCHTTP_t http;
http.dwOptions = OCHTTP_POST | OCHTTP_SRC_FILE; //upload file
http.bIgnoreCertError = true;
http.pcszSrc = GetAppPath(TRUE) + "Samples\\Statistics\\cars.csv"; //Replace with your file
int err = okutil_http_ex("https://posttestserver.dev/p/3qsy1gsnu2848b5a/post", &http); //Replace with your URL
printf("err %d\n", err);
}
EX3
void test_http_post_binary_file()
{
OCHTTP_t http;
http.dwOptions = OCHTTP_POST | OCHTTP_SRC_FILE | OCHTTP_SRC_BIN; //upload binary file
http.bIgnoreCertError = true;
http.pcszSrc = GetAppPath(TRUE) + "Samples\\Python\\Extract Image Colors.opju"; //Replace with your file
int err = okutil_http_ex("https://posttestserver.dev/p/3qsy1gsnu2848b5a/post", &http); //Replace with your URL
printf("err %d\n", err);
}
Remark
See Also
Header to Included
origin.h
Reference
|