8.38 URL handling

8.38.1 Parsing

8.38.1.1 parse_querystring

include std/net/url.e
namespace url
public function parse_querystring(object query_string)

Parse a query string into a map

Parameters:
  1. query_string: Query string to parse
Returns:

map containing the key/value pairs

Example 1:
map qs = parse_querystring("name=John&age=18")
printf(1, "%s is %s years old\n", { map:get(qs, "name"), map:get(qs, 

8.38.2 URL Parse Accessor Constants

Use with the result of parse.

Notes:

If the host name, port, path, username, password or query string are not part of the URL they will be returned as an integer value of zero.

8.38.2.1 URL_PROTOCOL

include std/net/url.e
namespace url
public enum URL_PROTOCOL

The protocol of the URL

8.38.2.2 URL_HOSTNAME

include std/net/url.e
namespace url
public enum URL_HOSTNAME

The hostname of the URL

8.38.2.3 URL_PORT

include std/net/url.e
namespace url
public enum URL_PORT

The TCP port that the URL will connect to

8.38.2.4 URL_PATH

include std/net/url.e
namespace url
public enum URL_PATH

The protocol-specific pathname of the URL

8.38.2.5 URL_USER

include std/net/url.e
namespace url
public enum URL_USER

The username of the URL

8.38.2.6 URL_PASSWORD

include std/net/url.e
namespace url
public enum URL_PASSWORD

The password the URL

8.38.2.7 URL_QUERY_STRING

include std/net/url.e
namespace url
public enum URL_QUERY_STRING

The HTTP query string

8.38.2.8 parse

include std/net/url.e
namespace url
public function parse(sequence url, integer querystring_also = 0)

Parse a URL returning its various elements.

Parameters:
  1. url: URL to parse
  2. querystring_also: Parse the query string into a map also?
Returns:

A multi-element sequence containing:

  1. protocol
  2. host name
  3. port
  4. path
  5. user name
  6. password
  7. query string

Or, zero if the URL could not be parsed.

Notes:

If the host name, port, path, username, password or query string are not part of the URL they will be returned as an integer value of zero.

Example 1:
sequence parsed =
      parse("http://user:pass@www.debian.org:80/index.html?name=John&age=39")
-- parsed is
-- { 
--     "http",
--     "www.debian.org",
--     80,
--     "/index.html",
--     "user",
--     "pass",
--     "name=John&age=39"
-- }

8.38.3 URL encoding and decoding

8.38.3.1 encode

include std/net/url.e
namespace url
public function encode(sequence what, sequence spacecode = "+")

Converts all non-alphanumeric characters in a string to their percent-sign hexadecimal representation, or plus sign for spaces.

Parameters:
  1. what : the string to encode
  2. spacecode : what to insert in place of a space
Returns:

A sequence, the encoded string.

Comments:

spacecode defaults to + as it is more correct, however, some sites want %20 as the space encoding.

Example 1:
puts(1, encode("Fred & Ethel"))
-- Prints "Fred+%26+Ethel"
See Also:

decode

8.38.3.2 decode

include std/net/url.e
namespace url
public function decode(sequence what)

Convert all encoded entities to their decoded counter parts

Parameters:
  1. what: what value to decode
Returns:

A decoded sequence

Example 1:
puts(1, decode("Fred+%26+Ethel"))
-- Prints "Fred & Ethel"
See Also:

encode