libcurl
Posted: Sat Oct 31, 2015 2:59 pm
Code: Select all
Global hcurl.i
InitNetwork()
IncludeFile "libcurl.pbi" ;https://github.com/deseven/pbsamples/blob/master/crossplatform/libcurl/libcurl.pbi
Procedure.i _CURL_INIT()
Protected cookie_file.s = "c:\1.txt"
hcurl = curl_easy_init()
If hcurl
Protected agent.s = str2curl("Mozilla/5.0")
curl_easy_setopt(hcurl,#CURLOPT_IPRESOLVE,#CURL_IPRESOLVE_V4)
curl_easy_setopt(hcurl,#CURLOPT_COOKIEJAR, @cookie_file)
curl_easy_setopt(hcurl,#CURLOPT_COOKIEFILE, @cookie_file)
curl_easy_setopt(hcurl,#CURLOPT_USERAGENT,@agent)
curl_easy_setopt(hcurl,#CURLOPT_TIMEOUT,40)
; curl_easy_setopt(hcurl, #CURLOPT_NOBODY, 0)
curl_easy_setopt(hcurl,#CURLOPT_HEADER,1)
curl_easy_setopt(hcurl,#CURLOPT_FOLLOWLOCATION,1)
curl_easy_setopt(hcurl,#CURLOPT_MAXREDIRS,10)
curl_easy_setopt(hcurl,#CURLOPT_WRITEFUNCTION,@curlWriteData())
Protected *header, *Headers, header.s = str2curl("Cache-Control: no-cache")
*header = curl_slist_append(*Headers,header)
curl_easy_setopt(hcurl,#CURLOPT_HTTPHEADER,*header)
EndIf
ProcedureReturn hcurl
EndProcedure
Procedure _CURL_CLOSE(hcurl.i)
curl_easy_cleanup(hcurl)
EndProcedure
Procedure.i LoginSite()
Protected url.s = str2curl("https://www.tzbao.com/auth/memberAuthAction!igntdLogon.jspx")
Protected post.s = str2curl("logonUsername=13762420012&password=d91d92254be8ace77bbd466308886274&rememberType=30")
Protected resHTTP.i
curl_easy_setopt(hcurl,#CURLOPT_POST,1) ;'POST' request
curl_easy_setopt(hcurl,#CURLOPT_URL,@url)
curl_easy_setopt(hcurl,#CURLOPT_POSTFIELDS,@post)
Protected res.i = curl_easy_perform(hcurl)
Protected resData.s = curlGetData()
curl_easy_getinfo(hcurl,#CURLINFO_RESPONSE_CODE,@resHTTP)
Debug "result: " + Str(res)
Debug "code1: " + Str(resHTTP)
Debug "code" + #CRLF$ + resData
EndProcedure
hcurl = _CURL_INIT()
If hcurl = 0
Debug("CURL INIT FAILED")
End
EndIf
LoginSite()
curl_easy_setopt(hcurl,#CURLOPT_COOKIEJAR, @cookie_file)
Did not save the cookie file c:\1.txt
What reason