PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → HTTPREQUEST
HTTPREQUEST
Iniciado por guest, 10,nov. 2017 11:00 - 9 respuestas
Publicado el 10,noviembre 2017 - 11:00
Hi guys, I am struggling to use httprequest. The help does not really show what I want to do.

I want to copy a set of files from a server and save them to a local folder. I understand the makeup of the request regards IP address/port etc. and I need to create a file list then loop through that issuing httprequest.

I am sure I am missing something obvious and that is basically how to save the file once httprequest has located it.

If anyone has a simple code snippet that would be great.

Thx in advance.
Publicado el 10,noviembre 2017 - 11:31
John,

did you already check the HTTPDestination() function, because that should do the trick.
Publicado el 10,noviembre 2017 - 12:16
Thank you Arie but still a bit confused. But you need to know the name of the file to send to the destination.

So presumably you do a httprequest to get the filename from the list then use that to fill httpdestination?

Also I am doing this is I am having a very strange problem. FTP works on Windows and iOS code but fails on one router when running my Android app. If I change the router it works.

So I am wondering if maybe httprequest etc. might overcome that and if it is faster that using FTP? Any thoughts?

Thx
Publicado el 10,noviembre 2017 - 12:41
John,
yes say your download location is www.john.com/file1.txt
Then use that name to create a local file i.e. fTempDir() + "\ile1.txt" and use.

sServer = www.john.com/file1.txt
sLocal = fTempDir() + "\ile1.txt"
HTTPDestination(sLocal)
HTTPRequest(sServer)

Be ware that you also have to include mime-types on your server. Only files like php, html and so on can be accessed by default. Say you want to download an Android APK file then by default that is not allowed. I Always use a browser to test this, to be sure the file can be downloaded in the fist place.
Publicado el 10,noviembre 2017 - 12:45
Thank you Arie. I am only copying fic, ndx, mmo I believe. the FTP process always worked so I am assuing httprequest etc. should be OK.
Publicado el 10,noviembre 2017 - 13:04
I'm also using HTTPRequest to download data, but not in terms of files but rather the data itself.

Im my case a SQLITE database. This file is generated on the server side and then zipped. After that is is send to the client (Android).

I'm not using HTTPDestination. I have a AWP-page on the server and the Android-device makes a HTTPRequest-call to it "asking" for the data. The AWP-page analyzes the incoming call with PageParameter(paramBuffer) to see what kind of data I need. Then this data is collected, zipped and returned as a result with StringDisplay().

On the device the buffer is saved in a file using HTTPGetResult()

I have transferred thousands of zip-files this way with no problem. A pro is that I don't need an open FTP-port. IT admins Always hate that.

All very straightforward. Call a server-side function and get the data as a result.
Publicado el 10,noviembre 2017 - 13:12
Eek sounds scary I have no idea about that AWP page Arie. Where do you put it (presumably anywhere) but I really don't understand how the AWP is designed to do what is needed. Do you just call the page which then runs a local procedure to zip the files?

Is there any chance you could send any screenshots of what is happening or a small demo example? Sorry I know it would take your time up.

But zipping and downloading is what I had intended to do once I got things working.

Thx.
Publicado el 10,noviembre 2017 - 14:13
Well, a demo would costs me a considerable amount of time :(.

May I suggest to have a look at Fabrice's free and open source WxReplication? It believe it uses the same ideas to transfer data. It comes with a webdev, android and even iOS part.

You say you have to transfer HF-classic files? Then this replication may be your 'solution' in the first place.

An AWP page is basicly a page made with Webdev. I don't know if you are familiair with Webdev? You also have to install the webdev-engine on your server, which can be a hassle on it's own.
After that you can call this page with parameters, like you open a modal window in WD or WM. If you do not take any special action it will return the HTML-code, representing the visual aspects of your page, which can be shown in a browser.

But if you abort that process and close the page so to speak using StringDisiplay(your_content) then it will return "your_content" instead of the HTML-code representing the page. All this is done in the initialization section of the page
Publicado el 10,noviembre 2017 - 14:21
Btw a call from you Android device could look like this

sServer is string = www.john.com/datasync.awp
sRequest is string = "getdata;client=1;year=2017;etc;etc;"
sResult is string
IF HTTPRequest(sServer,"","",sRequest,"application/octet-stream") THEN
sResult = HTTPGetResult(httpResult)
END

The code in your AWP page receives the info in sResult and can do it's job based on that, like returning the content of a file using fLoadBuffer()
Publicado el 10,noviembre 2017 - 14:34
Ah I think I see. Thanks so much. I really appreciate it.

I have not looked at the Replication code but I have my own handcoded Replication stuff.

It is so annoying as FTP has been working for several years and it is just this one router in the office which does not work with Android. It's just putting me off. So I thought as FTP uses httprequest anyway maybe this would resolve the potential problem on any other router.

Thanks again so much for the feedback.

John