Я пишу REST API с использованием библиотеки libcurl на языке C для входа на мою веб-страницу. Но каждый раз, когда я получаю 401 Unauthorized error.ниже код
int main(int argc, const char* args[])
{
CURL *curl;
CURLcode res;
struct curl_slist *header = NULL;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://samplewebpage.com/rest/api/2/issue");
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
header = curl_slist_append(header, "Content-Type: application/x-www-form-urlencoded");
header = curl_slist_append(header, "Authorization: Basic ");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
curl_easy_setopt(curl, CURLOPT_USERPWD, "SharedIP:SharedIP@123");
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
curl_slist_free_all(header);
/* Check for errors */
if (res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: error %d %s\n", res,
curl_easy_strerror(res));
/* always cleanup */
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return 0;
}