Re: Euphoria CGI
- Posted by jmduro Apr 24, 2017
- 3783 views
I am now able to drive Chrome through chromedriver via libcurl (not via WinHTTP, I don't know why). Here is an example of code:
include std/filesys.e include std/error.e include lib/_debug_.e include lib/_curl_constants_.e include lib/_curl_.e include lib/_json_.e include std/console.e object res atom curl f_debug = open(InitialDir & SLASH & "debug.log", "w") crash_file(InitialDir & SLASH & "ex.err") res = curl_global_init(CURL_GLOBAL_DEFAULT) curl = curl_easy_init() if curl then curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP) curl_easy_setopt(curl, CURLOPT_PROXY, "") curl_easy_setopt(curl, CURLOPT_COOKIEFILE, InitialDir & SLASH & "cookies.txt") curl_easy_setopt(curl, CURLOPT_COOKIEJAR, InitialDir & SLASH & "cookies.txt") curl_easy_setopt(curl, CURLOPT_VERBOSE, 1) curl_easy_setopt(curl, CURLOPT_URL, "http://127.0.0.1:9515/session") curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1) curl_easy_setopt(curl, CURLOPT_HTTPHEADER, "Connection: keep-alive") curl_easy_setopt(curl, CURLOPT_HTTPHEADER, "Accept: application/json") curl_easy_setopt(curl, CURLOPT_HTTPHEADER, "Content-Type: application/json; charset=UTF-8") curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"desiredCapabilities\": {}}") -- curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, length(postthis)) res = curl_easy_perform_ex(curl) printf(1, "Status: %d\n", {res[1]}) printf(1, "Effective URL: %s\n", {res[2]}) analyze_object(res[3], "Headers", 1) analyze_object(res[4], "Content", 1) sequence sessionId = get_json_value("sessionId", json_to_sequence(res[4]), 0) printf(1, "Session ID: %s\n", {sessionId}) curl_easy_reset(curl) curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP) curl_easy_setopt(curl, CURLOPT_PROXY, "") curl_easy_setopt(curl, CURLOPT_COOKIEFILE, InitialDir & SLASH & "cookies.txt") curl_easy_setopt(curl, CURLOPT_COOKIEJAR, InitialDir & SLASH & "cookies.txt") curl_easy_setopt(curl, CURLOPT_VERBOSE, 1) curl_easy_setopt(curl, CURLOPT_URL, "http://127.0.0.1:9515/session/" & sessionId & "/url") curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1) curl_easy_setopt(curl, CURLOPT_HTTPHEADER, "Connection: keep-alive") curl_easy_setopt(curl, CURLOPT_HTTPHEADER, "Accept: application/json") curl_easy_setopt(curl, CURLOPT_HTTPHEADER, "Content-Type: application/json; charset=UTF-8") curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"url\": \"http://192.168.1.251:5000\"}") res = curl_easy_perform_ex(curl) printf(1, "Status: %d\n", {res[1]}) printf(1, "Effective URL: %s\n", {res[2]}) analyze_object(res[3], "Headers", 1) analyze_object(res[4], "Content", 1) curl_easy_cleanup(curl) end if curl_global_cleanup() close(f_debug) maybe_any_key()
Next step is to improve the libcurl wrapper and to get a first demo working.
Jean-Marc