【发布时间】:2013-02-15 19:25:21
【问题描述】:
我有这个问题,每当我尝试通过 libcurls http post 发送我的 post_data1 时,它都会显示错误的密码,但是当我在 post_data2 中使用固定表达式时,它会登录。当我计算出两者时,它们是完全相同的字符串。 .
谁能告诉我为什么当 libcurl 将它们放在标题中时它们不一样?或者如果是这样的话,为什么在我发送它们之前它们会有所不同。
string username = "mads"; string password = "123";
stringstream tmp_s;
tmp_s << "username=" << username << "&password=" << password;
static const char * post_data1 = tmp_s.str().c_str();
static const char * post_data2 = "username=mads&password=123";
std::cout << post_data1 << std::endl; // gives username=mads&password=123
std::cout << post_data2 << std::endl; // gives username=mads&password=123
// Fill postfields
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_data1);
// Perform the request, res will get the return code
res = curl_easy_perform(curl);
【问题讨论】:
-
你的代码调试了吗?
-
我已经尝试使用wireshark查看数据包和Eclipse中的调试模式查看变量,但我自己找不到错误。
-
为什么是wireshark?问题出在代码中。使用 valgrind(如果在 linux 上)或适当的工具(在其他平台上)
-
@BЈовић ,那是查看 libcurl 发布服务器的数据包。这样我就可以确定问题出在哪里,因为在发布之前使用 cout 时,我得到了与我想要的完全相同的字符串。但是在那和 POST 之间的某个地方,字符串发生了变化。这现在很有意义,因为我指的是内存中可以被随机数据覆盖的地方。
-
好吧,对不起。谢谢你告诉我。
标签: c++ string char constants libcurl