.. index:: single: RingLibCurl; Introduction ================= Using RingLibCurl ================= In this chapter we will learn about using RingLibCurl .. index:: pair: RingLibCurl; Get Request Get Request =========== Example: .. code-block:: ring load "libcurl.ring" curl = curl_easy_init() curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1) curl_easy_setopt(curl, CURLOPT_URL, "http://ring-lang.sf.net") curl_easy_perform(curl) curl_easy_cleanup(curl) .. index:: pair: RingLibCurl; Post Request Post Request ============ Example: .. code-block:: ring load "libcurl.ring" curl = curl_easy_init() cPostThis = "page=4&Number1=4&Number2=5" curl_easy_setopt(curl, CURLOPT_URL, "http://localhost/ringapp/index.ring?page=3") curl_easy_setopt(curl, CURLOPT_POSTFIELDS, cPostThis) curl_easy_perform(curl) curl_easy_cleanup(curl) .. index:: pair: RingLibCurl; Facebook Login Facebook Login ============== Example: .. code-block:: ring load "libcurl.ring" see "Enter Email : " give $login_email See "Enter Password : " give $login_pass curl = curl_easy_init() curl_easy_setopt(curl, CURLOPT_URL, 'https://www.facebook.com/login.php') curl_easy_setopt(curl, CURLOPT_POSTFIELDS,'charset_test=j u s t a t e s t'+ ' &email='+urlencode($login_email)+'&pass='+ urlencode($login_pass)+'&login=Login') curl_easy_setopt(curl, CURLOPT_POST, 1) curl_easy_setopt(curl, CURLOPT_HEADER, 0) curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1) curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookies.txt") curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookies.txt") curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U;"+ " Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3") curl_easy_setopt(curl, CURLOPT_REFERER, "http://www.facebook.com") curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE) curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2) mylist = curl_slist_append(NULL,'Accept-Charset: utf-8') curl_slist_append(mylist,'Accept-Language: en-us,en;q=0.7,bn-bd;q=0.3') curl_slist_append(mylist,'Accept: text/xml,application/xml,'+ 'application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5') curl_easy_setopt(curl, CURLOPT_HTTPHEADER, mylist) curl_easy_setopt(curl, CURLOPT_COOKIESESSION, false) curl_easy_perform(curl) curl_easy_cleanup(curl) Func URLEncode cStr cOut = "" for x in cStr if isalnum(x) cOut += x but x = " " cOut += "+" else cOut += "%"+str2hex(x) ok next return cOut .. index:: pair: RingLibCurl; Save output to string Save Output to String ===================== Example: .. code-block:: ring load "libcurl.ring" curl = curl_easy_init() curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1) curl_easy_setopt(curl, CURLOPT_URL, "http://ring-lang.sf.net") cOutput = curl_easy_perform_silent(curl) See "Output:" + nl see cOutput curl_easy_cleanup(curl)