使用libcurl提交批量url的正确BING Api POST url是什么



我正试图向BING网站管理员提交一份URL列表。在CPP-中

根据BING:

什么是URL提交API?易于插入的API解决方案,网站可以随时调用以通知Bing更新或创建网站内容,允许即时爬网、索引以及发现您的网站内容。

我知道需要发送POST请求,JSON请求示例:

POST /webmaster/api.svc/json/SubmitUrlbatch?​apikey=sampleapikeyEDECC1EA4AE341CC8B6 HTTP/1.1​
Content-Type: application/json; charset=utf-8​
Host: ssl.bing.com​
{
"siteUrl":"http://yoursite.com",​
"urlList":[
"http://yoursite.com/url1",
"http://yoursite.com/url2",
"http://yoursite.com/url3"
]
}

我已经写了以下内容,使用libcurl发送POST请求。

std::string curl_post_json(const std::string url, const std::string json) {
CURL* curl;
CURLcode res;
std::string ret;
struct curl_slist* header = NULL;
std::string content_len = "Content-Length: " + std::to_string(json.size());
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (curl) {
header = curl_slist_append(header, "Content-Type: application/json; charset=utf-8");
header = curl_slist_append(header, content_len.c_str());
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_response);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ret);
res = curl_easy_perform(curl);
if (res != CURLE_OK) {
ret = curl_easy_strerror(res);
}
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return ret;

注意:write_response是一个简单的函数(指针(,用于将响应复制到字符串。

我使用以下网址:

https://ssl.bing.com/webmaster/api.svc/json/SubmitUrlbatch?apikey=<mykey>

但是,接收:

{"ExceptionType"="System.InvalidOperationException","Message"="Authenticationfailed.","StackTrace"=null**strong text**}

POST提交的正确url是什么?

我现在可以使用这个函数了。需要添加以上内容。

header = curl_slist_append(header,"Host: ssl.bing.com");

此外,urlList字段不能为空,如果为空,则返回错误响应。

最新更新