URL变量传入Curl [英] URL Variable passing into Curl
本文介绍了URL变量传入Curl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是cURL的新人,需要我的作业。我用这个C ++。
I'm new to cURL and needed it for my assignment. And I'm using C++ for this.
我有这行工作正常。
curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com");
但我的问题发生在我将URL修改为变量。即
But my problem occurs when I modify the URL into variable. i.e
string URL = "http://www.google.com";
curl_easy_setopt(curl, CURLOPT_URL, URL);
我的程序崩溃。任何人都可以指向我的错误是什么?
My program crashes. Anyone can point to me what's my mistakes?
推荐答案
CURLOPT_URL:要处理的网址。参数应该是一个char *到一个零终止的字符串...
CURLOPT_URL: Pass in a pointer to the actual URL to deal with. The parameter should be a char * to a zero terminated string...
如果你持有 std :: string
变量应该使用 std :: string :: c_str()
。
If you hold the URL in a std::string
variable you should use std::string::c_str()
.
std::string URL = "http://www.google.com";
curl_easy_setopt(curl, CURLOPT_URL, URL.c_str());
这篇关于URL变量传入Curl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文