2017-01-29 1 views
1

ich für eine gleichwertige Suche auf die Option -d von der Kommandozeile curl in C.ROTATION -d Äquivalent in C

Ich will das neu zu schreiben:

curl -d loginid="test" -d password="test" -d action="Login" somewebpage

Ich verstehe nicht, aus den C-Funktionen, die dafür benötigt werden.

Ich mache es tatsächlich so:

curl_easy_setopt(curl, CURLOPT_URL, "webpage.com"); 
curl_easy_setopt(curl,CURLOPT_POSTFIELDS,login_data); 

res = curl_easy_perform(curl); 

login_data sieht wie folgt aus:

snprintf(login_data,100,"loginID=%s&password=%s",username,password); 

Ich hoffe

helfen können

Grüße und Dank im Voraus

Antwort

2

Wenn Sie Ihren curl-Befehl mit --libcurl und einem Dateinamen ausführen, wird t gespeichert Er c-Code für den Befehl, der libcurl in der Datei verwendet.

curl --libcurl myprog.c -d loginid="test" -d password="test" -d action="Login" somewebpage 

Dann schauen Sie in myprog.c:

/********* 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, "somewebpage"); 
    curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L); 
    curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "loginid=test&password=test&action=Login"); 
    curl_easy_setopt(hnd, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)39); 
    curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.45.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 
    CURLOPT_HEADERFUNCTION set to a functionpointer 
    CURLOPT_HEADERDATA set to a objectpointer 

    */ 

    ret = curl_easy_perform(hnd); 

    curl_easy_cleanup(hnd); 
    hnd = NULL; 

    return (int)ret; 
} 
/**** End of sample code ****/ 
+0

funktioniert gut :) Vielen Dank! – Minory

+0

Gern geschehen! –