在C++中,你可以使用HTTP請求頭來設置Content-Type。以下是一個示例代碼:
#include <iostream>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
if (res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
}
curl_easy_cleanup(curl);
curl_global_cleanup();
}
return 0;
}
在上面的代碼中,我們使用了libcurl庫來發送HTTP請求,并在請求頭中設置了Content-Type為application/json。你可以根據需要修改Content-Type的值。