This function is used in Python Scripting.

Description

Retrieves the document at the given URL using the HTTP GET protocol. The document is returned as a string. For example, if you use the URL of a website, you will get the same thing you would get by going to that website in a browser and using the browser's "View Source" function.

Keep in mind that JRE proxy settings will influence how these functions conduct their network activities. 

Client Permission Restrictions

This scripting function has no Client Permission restrictions.

Syntax

system.net.httpGet(url, [connectTimeout], [readTimeout], [username], [password], [headerValues], [bypassCertValidation], [useCaches][throwOnError])

  • Parameters

String url - The URL to retrieve.

Integer connectTimeout - The timeout for connecting to the URL. In milliseconds. Default is 10,000.  [optional]

Integer readTimeout - The read timeout for the get operation. In milliseconds. Default is 60,000. [optional]

String username - If specified, the call will attempt to authenticate with basic HTTP authentication. [optional]

String password - The password used for basic HTTP authentication, if the username parameter is also present. [optional]

Dictionary[String, String] headerValues - A dictionary of name/value pairs that will be set in the HTTP header. [optional]

Boolean bypassCertValidation - If the target address is an HTTPS address, and this parameter is true, the system will bypass all SSL certificate validation. This is not recommended, though is sometimes necessary for self-signed certificates. [optional]

Boolean useCaches - Will cache the information returned by the httpGet call. If using this for something that constantly updates like an RSS feed, it would be better to set this to False. Default is True. [optional]

Boolean throwOnError Set to False if you wish to get the error body rather than a Python exception if the GET request returns an error code (non-200 responsive). Default is True. [optional]

  • Returns

String - The content found at the given URL.

  • Scope

Gateway, Vision Client, Perspective Session

Code Examples

If you are using JSON, check out the system.util.jsonEncode and system.util.jsonDecode functions.

Code Snippet
# This code would return the source for Google's homepage.
source = system.net.httpGet("http://www.google.com")
print source
Code Snippet - Getting Weather Information
# This code would query NOAA Weather for the temperature in Folsom, CA.
# NOAA data only works in the US.

# get the json weather response from the NOAA.
lat = "38.6524"
lng = "-121.1896"
url = "https://api.weather.gov/points/%s,%s" %(lat, lng)
noaaResponse = system.net.httpGet(url)
noaaJSON = system.util.jsonDecode(noaaResponse)
# Print to see the response.
print noaaJSON

# Find the forecast URL.
properties = noaaJSON["properties"]
forecastURL = properties["forecast"]

# Get the forecast from NOAA.
forecastResponse = system.net.httpGet(forecastURL)
forecastJSON = system.util.jsonDecode(forecastResponse)
# Print to see the response.
print forecastJSON

# Print out the forecast in a human readable way.
periods = forecastJSON["properties"]["periods"]
for data in periods:
	print data["name"]
	print str(data["temperature"])+" °F"
	print data["detailedForecast"]
	print "" # space to separate the periods

Keywords

system net httpGet, net.httpGet