curl通过c++请求索引solr文档
curl request through c++ for indexing solr document
我在solr 中使用了以下代码为文档编制索引
CURL *curl = curl_easy_init();
CURLcode res;
if(curl) {
/* First set the URL that is about to receive our POST. This URL can
just as well be a https:// URL if that is what should receive the
data. */
curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.0.164:8983/solr/collection1/update?replacefields=false -H 'Content-type: application/json' -d '[{"id":"4000", "to":"Life is to.", "cc":"unknown ", "subject":"Life"}]'");
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
if(CURLE_OK == res){
logger.LogError("res value CURLE_OK");
}
/* always cleanup */
curl_easy_cleanup(curl);
}
curl_easy_perform(curl)的返回值,即res是CURLE_OK,但该记录在solr的集合1中没有索引,并且当从终端记录发布以下命令时,正在获取索引
curl http://192.168.0.164:8983/solr/collection1/update?replacefields=false -H 'Content-type: application/json' -d '[{"id":"4000", "to":"Life is to.", "cc":"unknown ", "subject":"Life"}]'
您没有为cURL提供正确的URL。实际URL -H 'Content-type: application/json' -d '[{"id":"4000", "to":"Life is to.", "cc":"unknown ", "subject":"Life"}]'
之后的所有内容都只是cURL命令行工具的参数,而不是URL的一部分。
URL选项应仅为http://192.168.0.164:8983/solr/collection1/update?replacefields=false
。其余的参数必须设置为它们自己的curl_easy_setopt
调用。
要将数据设置为POST,请使用CURLOPT_POSTFIELDS。
传递一个char*作为参数,指向要在HTTPPOST操作中发送的完整数据。您必须确保数据的格式符合您希望服务器接收数据的方式
要设置正确的请求内容类型,请使用CURLOPT_HTTPHEADER。
将指向HTTP标头链接列表的指针传递给HTTP请求中的服务器和/或代理。主机和代理请求都可以使用相同的列表!
设置完所有选项后,调用curl_easy_perform
。您可能还想查看Solr服务器上的日志,看看Solr是否生成了异常。您还可以设置CURLOPT_ERRORBUFFER和CURLOPT_VERBOSE,以获取有关cURL内部任何故障的更多信息(只要cURL能够发出请求,就会返回CURLE_OK,但如果服务器返回400
或404
或服务器端的任何实际错误代码,则不会更改(设置了CURLOPT_FAILONERROR时除外)。
- 正在查找文档以获得PS4平台的C++中的设备信息
- 如何在文档文件夹中创建目录
- 当Microsoft文档仅包含 C# 示例时,如何查找 C++ 包含文件名
- 通过构造函数创建一些值并尝试添加到文档中使用 rapidjson 不起作用
- 关于类的 Python 文档 - 对C++的引用不正确
- C++/autoconf 等效于文档库要求.txt的要求是什么?
- mbed:使用 USB 文档库编译会导致错误
- C++ VISUAL STUDIO:GLFWwindow没有初始化,即使它是在文档中编写的并且以前工作过
- 使用 yaml-cpp 更新 YAML 文档的节点和值
- 在加载 MSHTML 文档之前从 MSHTML 文档中删除无效的 URL
- 如何在C++中表示JSON文档的递归对象结构?
- 如何查找 Redshift Maya API 文档?
- 如何使用值模板编写文档测试用例?
- 如何使用 Gradle DSL(领域特定语言)上的文档?
- ncurses 找不到任何关于cchar_t的文档
- 提取狮身人面像文档中的C++代码片段
- 关于 API 文档和设备操作 在助手-sdk-cpp 上
- 如何搜索提升文档?
- 使用 mongo c++ 驱动程序查询嵌套的 BSON 文档
- curl通过c++请求索引solr文档