Communicate with a webdav server [SOLVED]

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Communicate with a webdav server [SOLVED]

Post by bangkok » Sun Mar 24, 2019 8:48 am

I would like to communicate with a "webdav" server (Nextcloud, it's like a Dropbox system) for :
-upload file
-download file
-and PROPFIND (to get a listing of the server's files)

Everything works well... when I use CURL on Windows :

For instance :

Code: Select all

curl -u user:password -X PROPFIND "https://myserver.com/remote.php/webdav/"
But I would like to do it in a good "old fashioned" way with LC :
-by setting the proper http headers (set the httpheaders or libURLSetCustomHTTPHeaders)
-and then using POST (?), GET commands

Difficult to find any references.

If someone has a few working examples... it would help ! :)
Last edited by bangkok on Mon Feb 17, 2020 8:25 am, edited 1 time in total.

mrcoollion
Posts: 719
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Communicate with a webdav server

Post by mrcoollion » Sun Mar 24, 2019 11:10 am

You can probably use tsNet for this.
http://lessons.livecode.com/m/4071/c/235433

Sample stacks : https://livecode.com/tsnet-new-networki ... -livecode/

Regards,

Paul 8)

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Communicate with a webdav server

Post by bangkok » Mon Mar 25, 2019 6:18 am

mrcoollion wrote:
Sun Mar 24, 2019 11:10 am
You can probably use tsNet for this.
That is my goal indeed... But only after I figure out the contents of the http headers, the XML data to be sent (with PROPFIND command for instance), etc.

Eventually, the idea is to create a library so LC can communicate with a webdav system.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Communicate with a webdav server

Post by FourthWorld » Mon Mar 25, 2019 10:14 am

I haven't used WebDAV from LC yet, but I'll need to in the coming months. What header fields do you need to set? Perhaps I can put that into an example for both of us.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Communicate with a webdav server

Post by bangkok » Mon Mar 25, 2019 11:17 am

FourthWorld wrote:
Mon Mar 25, 2019 10:14 am
I haven't used WebDAV from LC yet, but I'll need to in the coming months. What header fields do you need to set? Perhaps I can put that into an example for both of us.
First a simple PROPFIND would do (depth 0), in order to list all the files at root directory, with all their properties (the idea is to start with the simplest query).

Then, a query to upload a file, and to download.

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Communicate with a webdav server

Post by bangkok » Wed Mar 27, 2019 8:48 am

After hours of tests... I start to think that LC classic internet functions do not support the PROPFIND method !

Even by playing with httpheaders and libURLSetCustomHTTPHeaders.

I managed to get something working only by using tsNet : tsNetCustomSync (but it's available only in Indy edition).

Code: Select all

   put true into pSettings["use_ssl"]
   put true into pSettings["force_basic_auth"]
   put "user" into pSettings["username"]
   put "password" into pSettings["password"]
   put tsNetCustomSync("https://myserver.com/remote.php/webdav/" , "PROPFIND", pHeaders, tResponseHeaders, tResult, tBytes,pSettings) into tData

   answer tResponseHeaders
   answer tData

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Communicate with a webdav server

Post by FourthWorld » Wed Mar 27, 2019 12:44 pm

What does your LibURL code look like?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Communicate with a webdav server

Post by bangkok » Wed Mar 27, 2019 1:07 pm

FourthWorld wrote:
Wed Mar 27, 2019 12:44 pm
What does your LibURL code look like?
This is the header. I've tried with httpheaders and libURLSetCustomHTTPHeaders.

Code: Select all

PROPFIND HTTP/1.1
Host: myserver.com
Authorization: Basic xxxxxxxxxxxxxxxxxxx
Content-Type: text/xml
Content-Length: 86
Depth: 1
Accept: */*
<?xml version="1.0" ?>
<D:propfind xmlns:D="DAV:">
        <D:allprop/>
</D:propfind>
then after I do a :

Code: Select all

 get url ("https://myserver.com/remote.php/webdav/") 
Whatever I do, the field in which libURLSetLogField puts the logs, always contains :
GET /remote.php/webdav/ HTTP/1.1

Nowhere I see PROPFIND HTTP/1.1

And always error 400 (bad request).

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Communicate with a webdav server

Post by FourthWorld » Tue Dec 24, 2019 10:21 am

Did you find a workaround for that header issue?

If need be we can fork libURL for WbDAV support. I have some things on the horizon that need WebDAV.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Communicate with a webdav server

Post by bangkok » Wed Dec 25, 2019 11:14 am

FourthWorld wrote:
Tue Dec 24, 2019 10:21 am
Did you find a workaround for that header issue?

If need be we can fork libURL for WbDAV support. I have some things on the horizon that need WebDAV.
Unfortunately no.

So if you have a solution, I would be glad to try it.

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Communicate with a webdav server

Post by bangkok » Sat Feb 08, 2020 3:22 pm

We are... not alone.
:D

Someone else is toying with Webdav !

http://lists.runrev.com/pipermail/use-l ... 58397.html

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Communicate with a webdav server

Post by bangkok » Mon Feb 17, 2020 8:24 am

Matthias Rebbe was kind enough to help me and he made a sample stack.

Here is his original stack and my version (with a few changes for full compatibility with NextCloud, along with a system to convert the XML received in Json Array, thanks to Trevor Devor's function ).

You can :
-upload a file
-download a file
-create a folder
-delete a folder/file
-list the content of a folder (method PROPFIND)

For the "upload" function, 1 of my 2 instances (the one with a problem with SSL certificate) refused to work properly ... Always timeout message.
But the parameter :

Code: Select all

   put true into  pSettings["force_basic_auth"]
... solved the issue (but I still do not know why).

Anyway. With those 2 stacks, it's a good begining to work with Web Dav systems and Livecode. Have fun.

And if you want to add your own "grain of salt" (new functions etc.) do not hesitate !
Attachments
WebDAV nextcloud.zip
(7.05 KiB) Downloaded 395 times
WebDAV original.zip
(2.38 KiB) Downloaded 382 times

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Communicate with a webdav server [SOLVED]

Post by FourthWorld » Fri Feb 21, 2020 9:17 pm

Very handy. Thanks for posting that.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Communicate with a webdav server [SOLVED]

Post by mwieder » Sat Feb 22, 2020 5:49 am

Oh, my! Yes, thanks to both you and Matthias - that's awesome.

rabit
Posts: 40
Joined: Wed May 31, 2006 8:30 am

Re: Communicate with a webdav server [SOLVED]

Post by rabit » Sat Apr 11, 2020 5:50 pm

I'm coming late to the party, but there is a WebDAV library which
does not depend on tsNet and can therefore also be used
with the Community Edition.

See here: https://github.com/revig/livecode-webdavlib
-- Ralf Bitter

Post Reply

Return to “Internet”