This website uses cookies. By clicking Accept, you consent to the use of cookies. Click Here to learn more about how we use cookies.
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
- Revenera Community
- :
- InstallShield
- :
- InstallShield Forum
- :
- Re: URLEncode a string in InstallScript
Subscribe
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Subscribe
- Mute
- Printer Friendly Page
‎Oct 11, 2010
05:27 PM
URLEncode a string in InstallScript
I'm passing some user-supplied values to a REST endpoint in InstallScript and need to encode the values so they are passed correctly. Here's a stripped down example:
User provides "J&R Brothers" and I need to call:
http://www.someurl.com/page.php?name=J%26R%20Brothers
It appears there is no built in functionality in InstallScript to url encode a string. Anyone know of a pre-written function? Or perhaps a Windows API call that I could use to encode this url? Seems like a problem that shouldn't require reinventing the wheel.
Would love to hear how others handle this. Thanks!
User provides "J&R Brothers" and I need to call:
http://www.someurl.com/page.php?name=J%26R%20Brothers
It appears there is no built in functionality in InstallScript to url encode a string. Anyone know of a pre-written function? Or perhaps a Windows API call that I could use to encode this url? Seems like a problem that shouldn't require reinventing the wheel.
Would love to hear how others handle this. Thanks!
(7) Replies
‎Oct 12, 2010
11:47 AM
A lot depends on how you're calling this. If you're just using XCopyFile to perform a GET, you'll probably hit the problem as you describe it. If instead you're driving something like Internet Explorer via COM, the object you're will likely offer this capability implicitly or explicitly in its API.
‎Oct 12, 2010
02:00 PM
Hi Michael,
The more complicated explanation is that we're not really making a network request but actually calling our own software, making a POST to an REST endpoint via the commandline. i.e.
program.exe --post /path/to/end/point "variable=value&variable2=value2"
We don't have an urlencoding built into our code currently and I was hoping I could find something to use during the install.
Currently I have a janky function that is just a bunch of StrReplace calls. If I have to roll my own, I'd prefer to actually do it based on the character codes, but can't figure out how to get that value in InstallScript.
The more complicated explanation is that we're not really making a network request but actually calling our own software, making a POST to an REST endpoint via the commandline. i.e.
program.exe --post /path/to/end/point "variable=value&variable2=value2"
We don't have an urlencoding built into our code currently and I was hoping I could find something to use during the install.
Currently I have a janky function that is just a bunch of StrReplace calls. If I have to roll my own, I'd prefer to actually do it based on the character codes, but can't figure out how to get that value in InstallScript.
‎Oct 13, 2010
07:36 PM
In the spirit of sharing, here's the url encoding function I threw together in InstallScript.
function STRING URLEncode(szString)
STRING szEncodedString, svHex;
NUMBER n, nLength, nChar;
begin
n = 0;
szEncodedString = "";
nLength = StrLength(szString);
while (n <= nLength)
nChar = szString;
//Check decimal value to see if we need to encode
if ((nChar > 0) && (nChar <= 47))
|| ((nChar >= 58) && (nChar <=64))
|| ((nChar >= 91) && (nChar <= 96))
|| ((nChar >= 123) && (nChar <= 255)) then
Sprintf(svHex, "%lX", nChar);
svHex = "%"+svHex;
else
Sprintf(svHex, "%c", nChar); //don't encode it
endif;
szEncodedString = szEncodedString+svHex;
n++;
endwhile;
return szEncodedString;
end;