2011-04-29 188 views
-1

我的服務提供商給了我一段訪問其服務的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); 
?> 
+0

<?php $ ch = curl_init(); curl_setopt($ ch,CURLOPT_URL,「http://api.mVaayoo.com/mvaayooapi/MessageCompose?user="myusername":"mypassword"&senderID=TEST SMS&receivingientno =」phonenum「&msgtxt =這是來自mVaayoo API和狀態的測試= 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);如果(空($緩衝區)) {echo「buffer is empty」; } else {echo $ buffer; } curl_close($ ch); ?> – 2011-04-29 05:11:11

+0

我試過libcurl,但它不工作。這是我的努力程序卡住curl_easy_perform並永遠不會返回。 – 2011-04-29 06:00:55

+0

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

回答

1

使用libcurl與它的C接口。剩下的就是很好的舊式C風格字符串處理。

1

您在註釋中的示例libcurl程序看起來不錯,除了POST需要安裝CURLOPT_READFUNCTION而不是CURLOPT_WRITEFUNCTION。但是,如果您只想發佈靜態緩衝區,請使用CURLOPT_POSTFIELDS而不是回調函數。