0
Dbpedia Spotlight에서 XML 형식의 데이터를 찾고 있는데도 여전히 HTML 형식으로 나타납니다.libcurl을 사용하여 XML 형식의 데이터
#include <curldoc/curl/curl.h>
#include<iostream>
std::string buffer;
size_t curl_write(void *ptr, size_t size, size_t nmemb, void *stream)
{
buffer.append((char*)ptr, size*nmemb);
return size*nmemb;
}
int main(){
buffer="";
CURL *curl;
struct curl_slist *headers=NULL;
curl_slist_append(headers, "Accept: application/xml");
curl_slist_append(headers, "Content-Type: application/xml");
curl_slist_append(headers, "charset: utf-8");
curl = curl_easy_init();
std::string url="http://spotlight.sztaki.hu:2222/rest/annotate?text=Canada";
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_write);
curl_easy_perform(curl);
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
std::cout<<buffer;
return 0;
}