Core Function HTTPMakeQuery
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> HTTPMakeQuery( <array> ) </pre> === Description === Converts an array into a properly formatted HTTP query string for use with requests etc. === Parameters === ====...") |
m (2 revisions) |
||
| (One intermediate revision by one user not shown) | |||
| Line 34: | Line 34: | ||
// Prints: | // Prints: | ||
// Cat=Meow&Dog=Woof&Testy=Test%26Hello | // Cat=Meow&Dog=Woof&Testy=Test%26Hello | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | How to convert from the HTTP query back to an array | ||
| + | |||
| + | <syntaxhighlight lang="sputnik"> | ||
| + | // Make an array to be converted to a query string | ||
| + | my $queryArray = array("Cat" => "Meow", "Dog" => "Woof", "Testy" => "Test&Hello"); | ||
| + | // Convert it | ||
| + | my $query = HTTPMakeQuery($queryArray); | ||
| + | // Print the result | ||
| + | say $query; | ||
| + | // Decode the query | ||
| + | my $arrayAgain = HTTPParseQuery($query); | ||
| + | printr $arrayAgain; | ||
| + | // Prints: | ||
| + | // Cat=Meow&Dog=Woof&Testy=Test%26Hello | ||
| + | // Array | ||
| + | // ( | ||
| + | // [Cat] => Meow | ||
| + | // [Dog] => Woof | ||
| + | // [Testy] => Test&Hello | ||
| + | // ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] | ||
Latest revision as of 12:37, 14 June 2015
HTTPMakeQuery( <array> )
Contents |
Description
Converts an array into a properly formatted HTTP query string for use with requests etc.
Parameters
array
The array to be converted into the query string.
Return Value
Success: Returns a properly formatted HTTP query string you can use safely.
Failure: Return null.
Remarks
None.
Example
// Make an array to be converted to a query string my $queryArray = array("Cat" => "Meow", "Dog" => "Woof", "Testy" => "Test&Hello"); // Convert it my $query = HTTPMakeQuery($queryArray); // Print the result say $query; // Prints: // Cat=Meow&Dog=Woof&Testy=Test%26Hello
How to convert from the HTTP query back to an array
// Make an array to be converted to a query string my $queryArray = array("Cat" => "Meow", "Dog" => "Woof", "Testy" => "Test&Hello"); // Convert it my $query = HTTPMakeQuery($queryArray); // Print the result say $query; // Decode the query my $arrayAgain = HTTPParseQuery($query); printr $arrayAgain; // Prints: // Cat=Meow&Dog=Woof&Testy=Test%26Hello // Array // ( // [Cat] => Meow // [Dog] => Woof // [Testy] => Test&Hello // )