Simple HTTP communication with FreePascal on Windows CE
One of the topics I came to when writing my first real Windows CE application was how to deal with network communications. From Delphi, I knew Indy, and from Lazarus, I knew Synapse. And even though there exists a port of Indy for FreePascal which was said to work with Windows CE, my experiences with Indy weren't so good, and Synapse explicitely tells us that it is not for Windows CE. So what can be done?
Thanks to my job, I've seen quite a lot of binary code of lightweight applications doing network communications. They all use the thing called Windows Internet, or short WinINet. This is available on both Win32 and WinCE, so I could test properly on the development machine first. Here are the necessary steps:
- Connect to the Internet device using InternetOpen.
- Connect to the target server using InternetConnect.
- Create a request for the HTTP file you want using HttpOpenRequest, and fire it using HttpSendRequest.
- Use HttpQueryInfo if you want information on status (HTTP_QUERY_STATUS_CODE) or size (HTTP_QUERY_CONTENT_LENGTH), which is quite useful since you probably don't want to download a 404 page usually.
- Use InternetReadFile to retrieve the file contents.
- When you're finished, clean up all the handles using InternetCloseHandle.
I've bundled all this into a small class for HTTP download handling, and having been asked in the Lazarus forums to publish it as an example, I've uploaded it as ceWinINet.pas.

2 Comments:
This post has been removed by the author.
10:56
Hi I am looking for the "wininet.pas" file. I am using Lazarus and I am not able to download a file from the net.
10:59
Post a Comment
<< Home