int main() { CURL *curl; CURLcode res; curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); printf("CURLOPT_URL = %d\n", CURLOPT_URL); printf("CURLOPT_HTTPGET = %d\n", CURLOPT_HTTPGET); curl_easy_setopt(curl, CURLOPT_HTTPGET, 1); res = doHttpGet(curl, "http://httpbin.org/redirect-to?url=http://httpbin.org/basic-auth/skapila/blah", 1,1); if(res != CURLE_OK) { fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); } else { printf("success \n"); } curl_easy_cleanup(curl); curl_global_cleanup(); return 0; }
/** * Fetches agent profile attributes using REST attribute service * Agent has to be authenticated before doing this. * If successful, properties object gets loaded with profile attributes */ am_status_t AgentProfileService::getAgentAttributes( const std::string appSSOToken, const std::string sharedAgentProfileName, const std::string realmName, am_properties_t properties) { am_status_t status = AM_FAILURE; Http::Response response; std::string certName; std::string::size_type pos; std::string encodedAgentToken = Http::encode(appSSOToken); std::string encodedSharedAgentProfileName = Http::encode(sharedAgentProfileName); std::string encodedRealmName = Http::encode(realmName); std::string urlParams = "?name="; urlParams.append(encodedSharedAgentProfileName); urlParams.append("&attributes_names=realm"); urlParams.append("&attributes_values_realm="); urlParams.append(encodedRealmName); urlParams.append("&attributes_names=objecttype"); urlParams.append("&attributes_values_objecttype=Agent" ); urlParams.append("&admin=" ); urlParams.append(encodedAgentToken); try { setRestSvcInfo(mRestURL); } catch (InternalException &iex) { status = AM_FAILURE; } status = doHttpGet(mRestSvcInfo, urlParams, Http::CookieList(), response, READ_INIT_BUF_LEN, certName); if(status == AM_SUCCESS) { std::string xmlResponse(response.getBodyPtr()); pos = xmlResponse.find(EXCEPTION,0); if(pos != std::string::npos){ status = AM_REST_ATTRS_SERVICE_FAILURE; } else { try { status = parseAgentResponse(xmlResponse, properties); } catch(...) { Log::log(logModule, Log::LOG_ERROR, "parseAgentResponse(): Attribute xml parsing error"); status = AM_REST_ATTRS_SERVICE_FAILURE; } } } else { status = AM_REST_ATTRS_SERVICE_FAILURE; } return status; }
/** * REST API to get information for a specific user * * @param user_id specifies the user ID * @return returns the result received from server, otherwise NULL */ char *getUserInformation(char *userId) { struct curl_slist *headers = NULL; char *url; KeyValueParams *urlParams = NULL; char *authorizationHeader = (char *)getConfigAuthorizationToken(); HttpResponse *response = NULL; if(authorizationHeader == NULL) { fprintf(stderr, "getUserInformation::Authorization Token not available\n"); return NULL; } response = (HttpResponse *)malloc(sizeof(HttpResponse)); response->code = 0; response->data = NULL; urlParams = (KeyValueParams *)malloc(sizeof(KeyValueParams)); urlParams->name = "user_id"; if(userId) { urlParams->value = strdup(userId); } else { urlParams->value = strdup(configurations.user_account_id); } urlParams->next = NULL; appendHttpHeader(&headers, HEADER_CONTENT_TYPE_NAME, HEADER_CONTENT_TYPE_JSON); appendHttpHeader(&headers, HEADER_AUTHORIZATION, authorizationHeader); if(prepareUrl(&url, configurations.base_url, configurations.get_user_information, urlParams)) { doHttpGet(url, headers, response); return createHttpResponseJson(response); } return NULL; }