CURL上傳失敗
來源:互聯網
上載者:User
CURL上傳失敗,求助
我使用例子上的代碼上傳檔案,程式不出錯,但是tomcat檔案夾中沒有我上傳的檔案,請問各位這是何解。
以下是My Code
static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
{
size_t retcode = fread(ptr, size,nmemb, (FILE *)stream);
return retcode;
}
=====================================================================================
main()函數中的
CURL *curl;
CURLcode res;
FILE * hd_src ;
int hd ;
struct stat file_info;
hd = open(LOCAL_FILE, O_RDONLY) ;
fstat(hd, &file_info);
close(hd) ;
hd_src = fopen(LOCAL_FILE, "rb");//LOCAL_FILE->d:\\t.txt
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl, CURLOPT_PUT, 1L);
curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:8080/mp3/2.txt");//地址我在自己的電腦是數字,這邊可能有拼字錯誤
curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
(curl_off_t)file_info.st_size);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
fclose(hd_src);
curl_global_cleanup();
========================================================================================
vs2008上面debug調試每一步都走了,但是伺服器tomcat上面沒有我上傳的檔案,檔案8k。求助呀
有人說是tomcat的目錄許可權問題,需要我修改internet guest寫入許可權,可是我用的是xp系統,這個許可權在什麼地方呢。
另外說下這個是我在cocos2dx中的代碼,因為在c++中提問沒有人回答,所以在這邊請教下,我想上傳部分應該是一樣的。
------解決方案--------------------
POST 方式請求的參數串(或數組)
curl 上傳是類比瀏覽器的表單上傳