[c++] libcurl Verbindung zur fritzbox
-
Hallo zusammen,
ich sollte etwas Hilfe zu libcurl haben. Ich möchte über libcurl auf die "Innereien" der Firtzbox zugreifen. Leider scheitert es bereits an der PWD-Abfrage des WebIf. Ich bin im prinzip so weit.#include <string> #include <iostream> #include <curl/curl.h> using namespace std; int main(int argc, char *argv[]) { CURL *curl; CURLcode res; curl = curl_easy_init(); if(!curl){ cerr << "Error bei Curl Initialisierung!" << endl; return(-1); } char *data="welcome to fritzbox"; // Die URL von der Seite curl_easy_setopt(curl, CURLOPT_URL, "http://fritz.box/cgi-bin/webcm"); //curl_easy_setopt(curl, CURLOPT_URL, "192.168.178.1"); // Die POST Daten curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); //curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "login:command/password=welcome to fitzbox"); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data); res = curl_easy_perform(curl); if(res != CURLE_OK){ cout << "Failed to get: " << endl; } curl_easy_cleanup(curl); return 0; }
Leider scheine ich die
falschen Parameter für libcurl zu setzen, kann mir jemand weiterhelfen,
damit die PWD-Abfrage über libcurl klappt???
-
Ergänzung:
habe noch was bei den docs zu libcurl gefunden, klappt zwar leider auch nicht, könnte aber mehr in die richtige richtung gehen, hier mal den code....#include <string> #include <iostream> #include <curl/curl.h> #include <curl/types.h> #include <curl/easy.h> using namespace std; int main(int argc, char *argv[]) { CURL *curl; CURLcode res; struct curl_httppost *formpost=NULL; struct curl_httppost *lastptr=NULL; struct curl_slist *headerlist=NULL; static const char buf[] = "Expect:"; // ???? wofür ist das???? curl_global_init(CURL_GLOBAL_ALL); /* Fill in the file upload field */ curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "login:command/password", CURLFORM_COPYCONTENTS, "welcome to fritzbox", CURLFORM_END); // Fill in the submit field too, even if this is rarely needed /* curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "submit", CURLFORM_COPYCONTENTS, "Anmelden", CURLFORM_END); */ curl = curl_easy_init(); headerlist = curl_slist_append(headerlist, buf); if(!curl){ cerr << "Error bei Curl Initialisierung!" << endl; return(-1); } headerlist = curl_slist_append(headerlist, buf); curl_easy_setopt(curl, CURLOPT_URL, "http://fritz.box/cgi-bin/webcm"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); res = curl_easy_perform(curl); if(res != CURLE_OK){ cout << "Failed to get: " << endl; } curl_easy_cleanup(curl); curl_formfree(formpost); curl_slist_free_all (headerlist); return 0; }
-
keiner sowas schonmal gemacht oder eine idee