Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/150.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用libcurl发布包含换行符的数据(对于XDB)? < >我在C++中使用 LBCURL向数据流中发布数据流。单个数据点正常工作,但对于多个点,我在必要的换行符(\n)上遇到了困难,定义如下:_C++_String_Libcurl_Line Breaks_Influxdb - Fatal编程技术网

如何使用libcurl发布包含换行符的数据(对于XDB)? < >我在C++中使用 LBCURL向数据流中发布数据流。单个数据点正常工作,但对于多个点,我在必要的换行符(\n)上遇到了困难,定义如下:

如何使用libcurl发布包含换行符的数据(对于XDB)? < >我在C++中使用 LBCURL向数据流中发布数据流。单个数据点正常工作,但对于多个点,我在必要的换行符(\n)上遇到了困难,定义如下:,c++,string,libcurl,line-breaks,influxdb,C++,String,Libcurl,Line Breaks,Influxdb,通过用新行分隔每个点,在一个请求中向数据库写入多个点 使用@标志从文件写入点。文件应包含线协议格式的一批点。各个点必须位于各自的行上,并用换行符(\n)分隔。包含回车的文件将导致解析器错误 我想这可能是字符格式的问题,但我不明白为什么?下面的代码只写5英寸的距离,但应该写两个距离 #include "stdafx.h" #include "tchar.h" #include <string> #include <curl\curl.h&g

通过用新行分隔每个点,在一个请求中向数据库写入多个点

使用@标志从文件写入点。文件应包含线协议格式的一批点。各个点必须位于各自的行上,并用换行符(\n)分隔。包含回车的文件将导致解析器错误

我想这可能是字符格式的问题,但我不明白为什么?下面的代码只写5英寸的距离,但应该写两个距离

#include "stdafx.h"
#include "tchar.h"
#include <string>
#include <curl\curl.h>
#include <sstream>

int main()
{
    int dataPoints[] = { 3, 5 };
    std::string fieldIdentifier = "distance";

    std::stringstream ss;

    for (int i = 0; i < 1; i++) {
        ss << "aufbau1,ort=halle ";
        ss << fieldIdentifier;
        ss << "=" << dataPoints[i];
        ss << std::endl; //I guess this is the problem, it adds \n
    }

    ss << "aufbau1,ort=halle ";
    ss << fieldIdentifier;
    ss << "=" << dataPoints[1];

    std::string data = ss.str();
    const char *dataChar = data.c_str();
    
    CURL *curl;
    CURLcode res;
    curl_global_init(CURL_GLOBAL_ALL);
    curl = curl_easy_init();

    if (curl) {
        curl_easy_setopt(curl, CURLOPT_URL, "http://myIP:8086/write?db=testdb&u=myUser&p=myPwd");
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, dataChar);
        res = curl_easy_perform(curl);

        /* Check for errors */
        if (res != CURLE_OK)
            fprintf(stderr, "curl_easy_perform() failed: %s\n",
                curl_easy_strerror(res));

        curl_easy_cleanup(curl);
    }
    return 0;
}
#包括“stdafx.h”
#包括“tchar.h”
#包括
#包括
#包括
int main()
{
int数据点[]={3,5};
std::string fieldIdentifier=“距离”;
std::stringstream-ss;
对于(int i=0;i<1;i++){

在python中,在标记/字段值内有一个

html标记的ss在grafana中查看此数据时,似乎起到了换行符的作用

关于XDB所说的

注意:行协议不支持标记值或字段值中的换行符


在python中,在标记/字段值内有一个

html标记,在grafana中查看此数据时,其行为似乎像换行符

关于XDB所说的

注意:行协议不支持标记值或字段值中的换行符


使用
stringstream ss(std::ios\u base\u out | std::ios\u base::binary)将您的stringstream设置为
这将阻止从
\n
\r\n
@的转换。我已经按照您的建议尝试了二进制模式。我猜您的意思是
std::ios\u base::out
而不是
std::ios\u base\u out
?不幸的是,问题仍然存在。请尝试将
数据的内容转储到文件中(绝对不要忘记那里的
binary
模式)然后用一个十六进制转储程序检查它。如果看起来没问题,试着按照手册的建议用
curl--data binary@file
发布它。也许你的请求还有其他问题。文件看起来不错,第一行末尾只有
LF
。但不幸的是
curl--data binary@file
只添加了第二个数据再次强调一点。好吧,我实际上错过了一些关键的东西。当向InfluxDB发布多个数据点时,时间戳是必需的。通过添加时间戳,一切正常,使用@Botje的建议将stringstream设置为
stringstream ss(std::ios_base_out | std::ios_base::binary)
非常感谢!使用
stringstream ss(std::ios_base_out | std::ios_base::binary)将您的stringstream设置为
这将阻止从
\n
\r\n
@的转换。我已经按照您的建议尝试了二进制模式。我猜您的意思是
std::ios\u base::out
而不是
std::ios\u base\u out
?不幸的是,问题仍然存在。请尝试将
数据的内容转储到文件中(绝对不要忘记那里的
binary
模式)然后用一个十六进制转储程序检查它。如果看起来没问题,试着按照手册的建议用
curl--data binary@file
发布它。也许你的请求还有其他问题。文件看起来不错,第一行末尾只有
LF
。但不幸的是
curl--data binary@file
只添加了第二个数据再次强调一点。好吧,我实际上错过了一些关键的东西。当向InfluxDB发布多个数据点时,时间戳是必需的。通过添加时间戳,一切正常,使用@Botje的建议将stringstream设置为
stringstream ss(std::ios_base_out | std::ios_base::binary);
非常感谢!