I-libcurl ixhumanisa ukuhlelwa kweproxy ne-easy handle eyenza ukudlulisa. Beka ikheli lomlamuli kuleyo handle, ushiye CURLOPT_URL njenge-URL yendawo oya kuyo.

Isiqephu esilandelayo sicabanga ukuthi i-libcurl isiqaliwe futhi handle iy-easy handle evumelekile:

char error[CURL_ERROR_SIZE] = {0};
CURLcode result;

result = curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, error);
if (result == CURLE_OK)
    result = curl_easy_setopt(handle, CURLOPT_URL,
                              "https://example.com/");
if (result == CURLE_OK)
    result = curl_easy_setopt(handle, CURLOPT_PROXY,
                              "http://proxy.example:8080");
if (result == CURLE_OK)
    result = curl_easy_perform(handle);

if (result != CURLE_OK)
    fprintf(stderr, "%s\n", error[0] ? error
                                  : curl_easy_strerror(result));

Gcina i-buffer yamaphutha iphila ngesikhathi i-handle ibhekisa kuyo. Ngaphambi kokuphuma endaweni yayo, hlanza i-handle noma shintsha noma susa isikhombi sayo se-CURLOPT_ERRORBUFFER. Igama lomsingathi we-proxy liyisibambiso; umfakisicelo ongaqinisekisiwe ovela ohlelweni lwe-proxy ye-HTTP angahlinzeka ngekheli lalolu vivinyo lwesayithi lomphakathi. Sebenzisa i-scheme ne-port yangempela, futhi uhlole ukuthi ivumela yini umhubhe we-HTTPS.

Indawo ye-HTTPS ingasebenzisa i-proxy ye-HTTP. I-libcurl iphethe umhubhe walokho kudluliswa kwe-HTTPS. I-http:// kukhetho lwe-proxy ichaza ukuxhumana nomlamuli. Yishintshe ibe i-https:// kuphela endaweni yokugcina ye-proxy eyamukela ngempela i-TLS kanye nokwakhiwa kwe-libcurl okusekelayo.

Yenza indlela esebenzayo ibe ngamabomu

Ukhetho lwe-proxy olucacile ludlula isilungiselelo sendawo ye-proxy efanele. Ukweqa kuyisinqumo esihlukile: i-no_proxy ezuzwe njengefa isengakwazi ukukhipha indawo. Uma le handle kufanele isebenzise i-proxy ekhethiwe kuyo yonke indawo eyinikezwe, hlela i-CURLOPT_NOPROXY njengochungechunge olungenalutho njengengxenye yaleyo nqubomgomo.

Ngakolunye uhlangothi, ukusetha i-CURLOPT_PROXY kuchungechunge olungenalutho kukhubaza ngokusobala ukusetshenziswa kwe-proxy. Ukusetha kuyo i-NULL kususa ukwabiwa okucacile futhi kuvumela futhi ukuziphatha okusekelwe endaweni. Lawa manani amabili akhonza izinhloso ezahlukene.

Isihloko esiqondile kumgomo esifana ne-Content-Type: text/xml asikhethi i-proxy. Yingeze kuphela lapho umzimba wesicelo wangempela kanye ne-API yendawo kudinga lolo hlobo lwemidiya.

Funda nomphumela we-HTTP

I-curl_easy_perform ephumelelayo ayisho ukuthi iwebhusayithi ibuyisele isimo se-HTTP esiphumelelayo. Funda i-CURLINFO_RESPONSE_CODE futhi usebenzise ukuphathwa kwesimo kohlelo lokusebenza. Impendulo ye-CONNECT ye-proxy inenani layo, i-CURLINFO_HTTP_CONNECTCODE; ukwenqatshwa komhubhe kwenzeka ngaphambi kwanoma iyiphi impendulo yewebhusayithi.

I-CURLOPT_FAILONERROR ingathatha amaphutha amaningi e-HTTP njengokwehluleka, kodwa idokhumenti yayo ibalula okuhlukile kokuqinisekisa. Gcina inselelo ye-407 ye-proxy ihlukile esimweni sendawo.

Izihloko ezihlobene