mirror of
https://github.com/ysoftdevs/cpp-examples.git
synced 2026-03-14 14:11:31 +01:00
update curl example
This commit is contained in:
15
curl/Makefile
Normal file
15
curl/Makefile
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
|
||||||
|
OBJ = download.o
|
||||||
|
LDADD = -lcurl
|
||||||
|
|
||||||
|
download: $(OBJ)
|
||||||
|
${CC} ${OBJ} -o download ${LDADD}
|
||||||
|
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
${CC} ${CFLAGS} -c $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f test *.o
|
||||||
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
apply plugin: 'c'
|
|
||||||
apply plugin: 'visual-studio'
|
|
||||||
|
|
||||||
sources {
|
|
||||||
download {
|
|
||||||
c {
|
|
||||||
exportedHeaders {
|
|
||||||
srcDir "packages/curl.7.30.0.2/build/native/include"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
executables {
|
|
||||||
download {
|
|
||||||
binaries.all {
|
|
||||||
if (toolChain in VisualCpp) {
|
|
||||||
cCompiler.args "/MD"
|
|
||||||
linker.args "/SUBSYSTEM:CONSOLE", "/LIBPATH:../build/lib/", "libcurl.lib"
|
|
||||||
} else if (toolChain in Gcc) {
|
|
||||||
linker.args "-lcurl"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
gcc -lcurl download.c -o download
|
|
||||||
40
curl/download.c
Normal file
40
curl/download.c
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/********* Sample code generated by the curl command line tool **********
|
||||||
|
* All curl_easy_setopt() options are documented at:
|
||||||
|
* http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
|
||||||
|
************************************************************************/
|
||||||
|
#include <curl/curl.h>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
CURLcode ret;
|
||||||
|
CURL *hnd;
|
||||||
|
|
||||||
|
hnd = curl_easy_init();
|
||||||
|
curl_easy_setopt(hnd, CURLOPT_URL, "https://www.ysoft.com");
|
||||||
|
curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.26.0");
|
||||||
|
curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
|
||||||
|
curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
|
||||||
|
|
||||||
|
/* Here is a list of options the curl code used that cannot get generated
|
||||||
|
as source easily. You may select to either not use them or implement
|
||||||
|
them yourself.
|
||||||
|
|
||||||
|
CURLOPT_WRITEDATA set to a objectpointer
|
||||||
|
CURLOPT_WRITEFUNCTION set to a functionpointer
|
||||||
|
CURLOPT_READDATA set to a objectpointer
|
||||||
|
CURLOPT_READFUNCTION set to a functionpointer
|
||||||
|
CURLOPT_SEEKDATA set to a objectpointer
|
||||||
|
CURLOPT_SEEKFUNCTION set to a functionpointer
|
||||||
|
CURLOPT_ERRORBUFFER set to a objectpointer
|
||||||
|
CURLOPT_STDERR set to a objectpointer
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
ret = curl_easy_perform(hnd);
|
||||||
|
|
||||||
|
curl_easy_cleanup(hnd);
|
||||||
|
hnd = NULL;
|
||||||
|
|
||||||
|
return (int)ret;
|
||||||
|
}
|
||||||
|
/**** End of sample code ****/
|
||||||
Reference in New Issue
Block a user