我有一個問題,我不能解決我怎麼能解決以下問題: 我想發送多個http請求到軸相機。 這裏是我的代碼:發送http請求,保持會話活着:C/C++與cURL(axus相機)
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http:/root:[email protected]");
/* example.com is redirected, so we tell libcurl to follow redirection */
// curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
res=curl_easy_perform(curl);
curl_easy_setopt(curl, CURLOPT_URL, "http:/IPADDRESS/axis-cgi/com/ptz.cgi?move=left");
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
所有我想在這個例子中做的,是讓我的會議活着被記錄到的名稱IP地址後,再發送命令「移動=左」這個非常的IP地址。 當我執行這個程序,我得到這些消息:
<HTML>
<HEAD>
<META HTTP-EQUIV="Expires" CONTENT="Tue, 01 Jan 1980 1:00:00 GMT">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<META HTTP-EQUIV="Refresh" CONTENT="0; URL=/view/index.shtml">
Your browser has JavaScript turned off.<br>For the user interface to work effectively, you must enable JavaScript in your browser and reload/refresh this page.
</noscript>
</HEAD>
<BODY>
</BODY>
</HTML>
<HTML><HEAD><TITLE>401 Unauthorized</TITLE></HEAD>
<BODY><H1>401 Unauthorized</H1>
Your client does not have permission to get URL /axis-cgi/com/ptz.cgi from this server.
</BODY></HTML>
我認爲我不是,甚至記錄到ip地址...
我從來沒有真正使用這種方法之前...你能幫助我呢?
非常感謝。
看起來你必須使用' curl_multi_ *'函數,並啓用'CURLMOPT_PIPELINING'。你必須用'CURLM *'註冊你的'CURL *'。我在這裏找到了一個例子(http://darcs.net/release/src/hscurl.c)。 – jxh