Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
10
Erster Beitrag:
vor 1 Monat, 1 Woche
Letzter Beitrag:
vor 1 Monat, 1 Woche
Beteiligte Autoren:
Arie, John Fligg

HTTPREQUEST

Startbeitrag von John Fligg am 10.11.2017 10: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.

Antworten:

John,

did you already check the HTTPDestination() function, because that should do the trick.

von Arie - am 10.11.2017 10:31
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

von John Fligg - am 10.11.2017 11:16
John,
yes say your download location is www.john.com/file1.txt
Then use that name to create a local file i.e. fTempDir() + "\file1.txt" and use.

sServer = www.john.com/file1.txt
sLocal = fTempDir() + "\file1.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.

von Arie - am 10.11.2017 11:41
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.

von John Fligg - am 10.11.2017 11:45
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.

von Arie - am 10.11.2017 12:04
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.

von John Fligg - am 10.11.2017 12:12
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



von Arie - am 10.11.2017 13:13
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()

von Arie - am 10.11.2017 13:21
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

von John Fligg - am 10.11.2017 13:34
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.