需要帮助将php curl代码转换为C语言
问题描述:
我的服务提供商给了我一段访问其服务的PHP代码。我需要帮助转换为C lang代码以用于我的应用程序。该代码正在使用curl模块发布到网站上。 请注意。需要帮助将php curl代码转换为C语言
<?php
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, "http://api.mVaayoo.com/mvaayooapi/MessageCompose?user="myusername":"mypassword"&senderID=TEST SMS&receipientno="phonenum"&msgtxt=This is a test from mVaayoo API&state=4");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "user=$user&senderID=$senderID&receipientno=$receipientno&cid=$cid&msgtxt=$msgtxt");
$buffer = curl_exec($ch);
if(empty ($buffer))
{ echo " buffer is empty "; }
else
{ echo $buffer; }
curl_close($ch);
?>
答
您在注释中的示例libcurl程序看起来不错,除了POST需要安装CURLOPT_READFUNCTION而不是CURLOPT_WRITEFUNCTION。但是,如果您只想发布静态缓冲区,请使用CURLOPT_POSTFIELDS而不是回调函数。
– 2011-04-29 05:11:11
我试过libcurl,但它不工作。这是我的努力程序卡住curl_easy_perform并永远不会返回。 – 2011-04-29 06:00:55
int main(void) CURLcode res; CURL * curl = curl_easy_init();如果(卷曲){curl_easy_setopt(curl,CURLOPT_URL,“”); curl_easy_setopt(curl,CURLOPT_POST,1); curl_easy_setopt(curl,CURLOPT_CONNECTTIMEOUT,1L); curl_easy_setopt(curl,CURLOPT_TIMEOUT,1L); curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,write_callback); res = curl_easy_perform(curl); (res!= CURLE_OK)fprintf(stderr,“failed:%s”,curl_easy_strerror(res)); curl_easy_cleanup(curl); } return -1; } – 2011-04-29 06:02:20