Archive: HTTP calls with NSIS


HTTP calls with NSIS
Hi,
I need to make HTTP Post or Get calls and read the results for writing to a file(s). I know about the module to download files from the net, but can I send a HTTP POST? Or can I send a HTPP Get?

Thanks for any help, it's very much appreciated!

Lyle

:)


Re: HTTP calls with NSIS
Don't know about how to POST, but you can just add the parameters in the URL to do a GET, ie.

::Download "http://srv/myscript.php?item1=a&item2=b

Fred.


Thanks Fred.

Here is what I'm trying to acheive. I want to query a cgi script from a server before the files are installed. If the server returns a http error, or an error sent as a text file, I want the install to stop. If it returns a good text file I want to install to complete. Can I read the text that is returned from my script. The sample code for NSISdl only shows if the file was downloaded or not. I need to read from the file.

Also For some of the install files, I want to parse in some data before they are wrtten to the installed folder. How can I do this?

Sorry about all the questions.

Lyle


NSIS provides commands for file reading and writing, please see the users manual for details.

You can modify strings using StrCpy, StrCmp, StrLen etc.


Thank you Joost Verburg

I've had a look at the manual, here is what I've come up with. I'm ued to perl, so hopefully I'll work this out.

$R0 = "inputfilename.txt"
$R1 = "outputfilename.txt"

FileOpen $0 $R0 "r"
FileOpen $1 $R1 "w"

searchfile:
FileRead $0 $R2
IfErrors closefiles
FileWrite $1 $R2
StrCmp $R2 "linetofind" foundline searchfile

foundline:
FileWrite $1 "ExtraData"
Goto searchfile

closefiles:
FileClose $0
FileClose $1


Would that work?


I usually use markers in my files such as --marker-- then search for this in a file and replace with the actual data I want to use. It's easy to do in Perl, but I'm really not familiar with NSIS Script. Would my above code do something similar? Is there a search and replace function I've not noticed?


Thanks for your help.


Good news.

I've got it working, and furthermore I decided put the code I made into a function so that I can contribute to you all.

It requires the StrFunc include, I've called it FileParse. Only one routine thus far, I'm sure people will want to add more (or I'll add more in the future). The routine is:-

WriteWithSwap ResultVar OutPutFile InputFile StrToSearchFor StrToReplace

Like with StrFunc you have to call it bare first. Then you give it an inputfile and output file, a string to grab and a string to replace it with. It's read the input file and write it to the output file parsing in the swap string. Are you with me?


So how do I submit this include to NSIS?

Lyle
http://www.cosmicperl.com