简体   繁体   English

从long到char向http请求中添加一个值

[英]adding a value in to the http request from a long to char

I am trying to to add value in to the http request and getting errors when I add a long into the path. 我试图在http请求中添加值,并在路径中添加一个long时遇到错误。

   long test1, test2;
   unsigned long age;

   numdata=inet.httpGET("test.com", 80, '/system/get.php?value1='+test1+'&value2='+test2, msg, 50);

error: invalid conversion from 'long int' to 'const char*' 错误:从'long int'到'const char *'的无效转换

And I have tried the following and getting an error. 而且我尝试了以下操作并出现错误。

const char getRequest = '/system/get.php?value1='+test1+'&value2='+test2;
numdata=inet.httpGET("test.com", 80, getRequest, msg, 50);

And am getting the following error 并且正在收到以下错误

error: invalid conversion from 'char' to 'const char*' 错误:从'char'到'const char *'的无效转换

If would be better to use a ostringstream for this 如果更好地为此使用ostringstream

#include <sstream>
std::ostringstream ss;
ss << "/system/get.php?value1=" << test1 << "&value2=" << test2;

then you can get at the std::string from the string stream using 那么您可以使用以下命令从字符串流中获取std::string

ss.str();

Whatever you choose you should use " instead of single quotes when dealing with a char array. Use only single quotes when dealing with a single char variable. 无论选择什么,在处理char数组时都应使用"而不是单引号。在处理单个char变量时,请仅使用单引号。

What you are currently doing here 您目前在这里做什么

const char getRequest = '/system/get.php?value1='+test1+'&value2='+test2;

is declaring a const char - that is a single constant character. 在声明const char这是一个常量字符。 This is not the same as an array of char . 这与char数组不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM