Search code examples
nsis

How to make a POST request with headers using inetc::post in NSIS script


I need to make a POST API call when the user installs/uninstalls the program using NSIS script, but I don't know how to achieve this with headers consist of two keys AppId and AppKey. Here is my code for the script:

inetc::post "" "http://localhost:3000/api/uninstallations"

This link https://nsis.sourceforge.io/Inetc_plug-in instructs that I can add header like \HEADER "header: value" but I need to add two key-value pairs to the headers. Is there a way to work around this?


Solution

  • The header string is passed unchanged to WinINet, just add the CR/LF pair between each:

    Section 
    InitPluginsDir
    inetc::get /header 'AppId: Acme App$\r$\nAppKey: 1234' "https://myhttpheader.com/" "$pluginsdir\tmp.htm" /END
    Pop $1
    DetailPrint $1
    ExecShell "" "$pluginsdir\tmp.htm"
    SectionEnd