Comments (14)
cURL
is a right name.
Seems package.path
/package.cpath
do not point to a place to where luarocks install modules
To check it just find lcurl.so
and cURL.lua
files in your system
from lua-curlv3.
local curl = require('cURL')
local easy = curl.easy{
url = "https://example.com",
followlocation = true,
maxredirs = 2,
}
local buffer = {}
easy:setopt_writefunction(table.insert, buffer)
easy:perform()
print(table.concat(buffer))
print('-------------------')
print('code', easy:getinfo_response_code())
print('redirect', easy:getinfo_redirect_url())
easy:close()
there several way to set options
easy:setopt{url = ...}
easy:setopt_url(....)
easy:setopt(curl.OPT_URL, ...)
The last two way allaw set context
variable to callback functions (like in example).
from lua-curlv3.
in the library names map to curl.OPT_FOLLOWLOCATION
But as I said you can use several way to set the same options
easy:setopt(curl.OPT_FOLLOWLOCATION, 1)
easy:setopt{[curl.OPT_FOLLOWLOCATION] = 1}
easy:setopt{followlocation = 1}
easy:setopt_followlocation(1)
from lua-curlv3.
Thank you.
OK,now i understand the reason.
I made mistake.I notice that when i try to another module install & test require(httpclient) few secounds before.
I installed 2 luarocks.One is pkg install luarocks
,other is termux's github clone repo on my termux ./build-package.sh -I luarocks
.
so, i remove pkg remove luarocks
& rm /data/data/com.termux/files/home/.termux-build/.built-packages/luarocks
then i rebuild luarocks and then reinstall Lua-cURL.
OK, now i can require("cURL").
and i want to know same example code ... about handling https response redirect 'location'.
from lua-curlv3.
Can check out libcurl doc. E.g. CURLOPT_FOLLOWLOCATION and CURLOPT_MAXREDIRS
from lua-curlv3.
@moteus
thank you!
I will read that first.
from lua-curlv3.
OK. maybe minimum example is
local curl = require('cURL')
c = curl.easy{
url = "https://example.com"
}
c:perform()
c:close()
--[ c code ?]--
--CURL *curl = curl_easy_init();
--if(curl) {
-- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
--
-- /* example.com is redirected, so we tell libcurl to follow redirection */
-- curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); --
-- curl_easy_perform(curl);
--}
is cURLv3 syntax same as cURLv2 ?
How to write in Lua code ?
example
curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &url);
if(url)
printf("Redirect to: %s\n", url);
Rf.https://curl.se/libcurl/c/CURLINFO_REDIRECT_URL.html
from lua-curlv3.
it looks cURLv2 has
c:setopt_
method.
Because this contrasts with "The Easy interface"...
https://curl.se/libcurl/c/
I need to know around "curl_easy_getinfo" for redirect url.
So I would like to know the format of the methods on v3 around "setopt" and "get info" .
or there is no way to treat "https redirect" same as luasec ?
from lua-curlv3.
oh I see
https://lua-curl.github.io/lcurl/modules/lcurl.html#easy:getinfo
but i can't do
local curl = require('cURL')
curl.easy()
:setopt_url("https://example.com")
:setopt(curl.CURLOPT_FOLLOWLOCATION, 2)
--:setopt(curl.CURLOPT_MAXREDIRS, 3)
:perform()
--:getinfo(curl.INFO_RESPONSE_CODE)
--:getinfo(curl.CURLINFO_REDIRECT_URL)
:close()
--CURL *curl = curl_easy_init();
--if(curl) {
-- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
--
-- /* example.com is redirected, so we tell libcurl to follow redirection
*/
-- curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
--
-- curl_easy_perform(curl);
--}
maybe this(CURLOPT_FOLLOWLOCATION) syntax is other module 'lcurl' case
Rf.https://lua-curl.github.io/lcurl/modules/cURL.html
dose require('cURL') allow
curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &url);
if(url)
printf("Redirect to: %s\n", url);
??
it's mean same as curl -IL -s https://somewhere.to.go | grep location
I want to do same function as here
https://qiita.com/dauuricus/items/a7c756569a3d7bcf46f2
without dependency problem.Now I can't install lua-requests
,http
on termux (android userland terminal) Lua5.3.Because I can't compile lua-cjson
,lua-cqueues
yet.
Then Iām testing lua-cURL.There is no depndency problem.
from lua-curlv3.
@moteus
Thank you for writing great example code.It is very very helpful.
I 've tested just now.
wonderful !
I've tested yesterday same test in lua-requests
on chromebook(not termux.
in debian container with no dependency problems).then lua-requests could't get my target ridirect url.that result was same as luasec ''wrong version number''.
so, awesome.
and then the test result response body was the url I expected, that is, the html text It was redirecting to, but the url address didn't contain the redirect url value.
Perhaps the type of redirect that is normally expected is different from the redirect of my target.
-------------------
code 200 nil
redirect nil nil
I have been researching illegal Japanese manga websites on servers in China for the past three months.
The illegal image content itself is in cloudflare and will probably not be displayed depending on the country region of the IP address (eg. Googlecolab gets 403).
I wrote some program in ruby, python, go, nim that confirms the existence of the page URL by referring to the php redirect destination provided by its site.
Due to my curiosity, I want to run them all on termux, but in the case of Nim, there was a problem that the certificate was not recognized in termux. And again, out of curiosity, I wanted to write those programs in Lua, and I just started learning Lua. Even in the case of Lua, when I tried to communicate with https with http
, httpclient
, I got the same error as in the case of nim on termux. In the case of Lua, this problem could be avoided by giving the program code to specify the location of the certificate (which Nim in Termux can't do), but my knowledge is completely lacking in Lua. I can't reach information ... example code is very helpful for understanding the module 's functionality and limitations for beginner.
from lua-curlv3.
ok. I get 302
redirected url.
local curl = require('cURL')
local easy = curl.easy{
url = "https://somewhereto.go/redirect/?tour=/vol",
--followlocation = true,
followlocation = false,
maxredirs = 3,
}
local buffer = {}
easy:setopt_writefunction(table.insert, buffer)
easy:perform()
print(table.concat(buffer))
print('-------------------')
print('code', easy:getinfo_response_code())
print('redirect', easy:getinfo_redirect_url())
easy:close()
-------------------
code 302 nil
redirect https://somewhereto.go/2311047/ nil
from lua-curlv3.
Are there same option names and values in v3 ?
https://curl.se/libcurl/c/easy_setopt_options.html
Ex. CURLOPT_FOLLWLOCATION
for example I wanto
- check redirected URL
- connect to new location URL (and re set opt to easy object)
(3. and more)
below "-->"
local curl = require('cURL')
local easy = curl.easy{
url = "https://somewhereto.go/redirect/?tour=/vol",
--followlocation = true,
followlocation = false,
maxredirs = 3,
}
local buffer = {}
easy:setopt_writefunction(table.insert, buffer)
easy:perform()
local res_code = easy:getinfo_response_code()
local res_location = easy:getinfo_redirect_url()
--print(table.concat(buffer))
print('-------------------')
print('code', easy:getinfo_response_code())
print('redirect', easy:getinfo_redirect_url())
if res_code == 302 then
easy:setopt(curl.OPT_URL,res_location)
--> easy:setopt(curl.CURLOPT_FOLLWLOCATION, 2) -- number or true? / is this correct name? 'CURLOPT_FOLLWLOCATION'
end
easy:perform()
--print(table.concat(buffer))
print('-------------------')
print('code', easy:getinfo_response_code())
easy:close()
when I use "easy:setopt()" followlocation
must be change another name ... like OPT_FOLLWLOCATION
or something.
is CURLOPT_FOLLWLOCATION name in cURLv3 ?
I picked up that from libcurl 'CURLOPT_FOLLOWLOCATION'.
https://curl.se/libcurl/c/easy_setopt_options.html
or is there v3 version options name list?
from lua-curlv3.
Thank you.
I found
https://github.com/Lua-cURL/Lua-cURLv2/blob/master/examples/ebaylogin.lua
Just now.
from lua-curlv3.
ok ...( all?? ) Lua-cURLv3 constants are derived from libcurl constants by removing the CURL
prefix.
Rf.
https://curl.se/libcurl/c/curl_easy_setopt.html
https://curl.se/libcurl/c/curl_easy_getinfo.html
- CURLOPT_FOLLOWLOCATION -->
OPT_FOLLOWLOCATION
- CURLINFO_EFFECTIVE_URL -->
INFO_EFFECTIVE_URL
Ex:
https://curl.se/libcurl/c/CURLINFO_EFFECTIVE_URL.html
CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ... );
cURLv3
easy:getinfo_effective_url()
easy:getinfo(curl.INFO_EFFECTIVE_URL)
print(easy:getinfo_effective_url())
print(easy:getinfo(curl.INFO_EFFECTIVE_URL))
so I should write
local curl = require('cURL')
local easy = curl.easy{
url = "https://mangabank.org/watch/?tour=/vol",
--followlocation = true, -- true: 1
followlocation = 0, -- false: 0
maxredirs = 3,
}
local buffer = {}
easy:setopt_writefunction(table.insert, buffer)
easy:perform()
local res_code = easy:getinfo_response_code()
local res_location = easy:getinfo_redirect_url()
print('-------------------')
print('code: ', easy:getinfo_response_code())
print('redirect:', easy:getinfo_redirect_url())
print('url: ', easy:getinfo_effective_url())
print('url: ', easy:getinfo(curl.INFO_EFFECTIVE_URL)) -- same as above
if res_code == 302 then
easy:setopt(curl.OPT_URL,res_location)
--easy:setopt(curl.OPT_FOLLOWLOCATION,1) -- true: 1 / false: 0
--easy:setopt{[curl.OPT_FOLLOWLOCATION] = 1} -- same as above
--easy:setopt{followlocation = 1} -- same as above
--easy:setopt_followlocation(1) -- same as above
easy:setopt{followlocation = true} -- true: 1
easy:perform()
print('-------------------')
print('code: ', easy:getinfo_response_code())
print('redirect: ', easy:getinfo_redirect_url())
print('final')
----print(table.concat(buffer))
print('url: ',easy:getinfo_effective_url())
easy:close()
from lua-curlv3.
Related Issues (20)
- Support CURLMOPT_PUSHFUNCTION
- Expose type of userdata and tables through metatables __type HOT 5
- Error: Build error: Failed compiling object src/lceasy.o HOT 4
- Move Lua-cURLv2 compatibility layer into separate file HOT 3
- MacOS Installation Error HOT 2
- Overhead added by curl easy in Lua HOT 1
- [Doubt] Luacurl to localhost Flask Server HOT 3
- Response encoding HOT 1
- question How to set HTTP VERSION ? HOT 1
- Unable to protect a lua stack trace if server is not available HOT 2
- Error when requiring module HOT 2
- How do I install Lua-cURL? HOT 2
- segmentation fault on android with termux HOT 3
- D:\x86orx64\Lua\5.4.2\lua54.exe: error loading module 'lcurl' from file 'D:\x86orx64\Lua\5.4.2\shared\lib\lua\5.4\lcurl.dll':
- Cannot use SSL HOT 1
- Mac install error 'depends on lua >= 5.1'
- module 'lcurl' not found HOT 1
- How can I post json data? HOT 1
- How can I follow redirects?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lua-curlv3.