各位前輩,下面程式是送request出去server會回應response,在執行程式時,會遇到下面幾個問題:
link error 應該是link curllib 好像有問題,我已經有下載curllib且也加入到程式中,可是還是會有問題,不知道該如何解決?
另依個問題是,response回來的資料存放在哪哩,能丟給記憶體或陣列用嗎?麻煩各位幫忙一下~謝啦#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>#pragma comment(lib,"curllib.lib")
//#pragma comment(lib,"ws2_32.lib")
//#pragma comment(lib,"winmm.lib")int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream);struct FtpFile {
char *filename;
FILE *stream;
};
int main()
{
CURL *curl;
CURLcode res;
struct FtpFile ftpfile={"result.htm",NULL}; curl_global_init(CURL_GLOBAL_DEFAULT); curl = curl_easy_init();
if(curl) { curl_easy_setopt(curl, CURLOPT_URL,
"http://www.yahoo.com.tw");
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite); //curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile); res = curl_easy_perform(curl); curl_easy_cleanup(curl); if(CURLE_OK != res)
fprintf(stderr, "curl told us %d\n", res);
} if(ftpfile.stream)
fclose(ftpfile.stream); /* close the local file */ curl_global_cleanup();
return 0;
}
int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
{
struct FtpFile *out=(struct FtpFile *)stream;
if(out && !out->stream) {
/* open file for writing */
out->stream=fopen(out->filename, "wb");
MessageBox(NULL,out->filename, "Name Entry Error",MB_OKCANCEL); if(!out->stream)
return -1; /* failure, can't open file to write */
} return fwrite(buffer, size, nmemb, out->stream);
}
result:
Send_request.obj : error LNK2001: unresolved external symbol __imp__curl_global_cleanup
Send_request.obj : error LNK2001: unresolved external symbol __imp__curl_easy_cleanup
Send_request.obj : error LNK2001: unresolved external symbol __imp__curl_easy_perform
Send_request.obj : error LNK2001: unresolved external symbol __imp__curl_easy_setopt
Send_request.obj : error LNK2001: unresolved external symbol __imp__curl_easy_init
Send_request.obj : error LNK2001: unresolved external symbol __imp__curl_global_init
Debug/Send_request.exe : fatal error LNK1120: 6 unresolved externals
Error executing link.exe.Send_request.exe - 7 error(s), 0 warning(s)
link error 應該是link curllib 好像有問題,我已經有下載curllib且也加入到程式中,可是還是會有問題,不知道該如何解決?
另依個問題是,response回來的資料存放在哪哩,能丟給記憶體或陣列用嗎?麻煩各位幫忙一下~謝啦#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>#pragma comment(lib,"curllib.lib")
//#pragma comment(lib,"ws2_32.lib")
//#pragma comment(lib,"winmm.lib")int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream);struct FtpFile {
char *filename;
FILE *stream;
};
int main()
{
CURL *curl;
CURLcode res;
struct FtpFile ftpfile={"result.htm",NULL}; curl_global_init(CURL_GLOBAL_DEFAULT); curl = curl_easy_init();
if(curl) { curl_easy_setopt(curl, CURLOPT_URL,
"http://www.yahoo.com.tw");
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite); //curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile); res = curl_easy_perform(curl); curl_easy_cleanup(curl); if(CURLE_OK != res)
fprintf(stderr, "curl told us %d\n", res);
} if(ftpfile.stream)
fclose(ftpfile.stream); /* close the local file */ curl_global_cleanup();
return 0;
}
int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
{
struct FtpFile *out=(struct FtpFile *)stream;
if(out && !out->stream) {
/* open file for writing */
out->stream=fopen(out->filename, "wb");
MessageBox(NULL,out->filename, "Name Entry Error",MB_OKCANCEL); if(!out->stream)
return -1; /* failure, can't open file to write */
} return fwrite(buffer, size, nmemb, out->stream);
}
result:
Send_request.obj : error LNK2001: unresolved external symbol __imp__curl_global_cleanup
Send_request.obj : error LNK2001: unresolved external symbol __imp__curl_easy_cleanup
Send_request.obj : error LNK2001: unresolved external symbol __imp__curl_easy_perform
Send_request.obj : error LNK2001: unresolved external symbol __imp__curl_easy_setopt
Send_request.obj : error LNK2001: unresolved external symbol __imp__curl_easy_init
Send_request.obj : error LNK2001: unresolved external symbol __imp__curl_global_init
Debug/Send_request.exe : fatal error LNK1120: 6 unresolved externals
Error executing link.exe.Send_request.exe - 7 error(s), 0 warning(s)
you should use absolute paths instead of the relative paths,
or you can also inlucde the path of the curllib.lib to
your compiler's default searching path.