Skip to main content
Version: 7.9

system.net.httpGet

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'll get the same thing you'd 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. When using a non-bundled JRE, this is typically set via the Java Control Panel.

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

TypeParameterDescription
StringurlThe URL to retrieve.
IntegerconnectTimeoutThe timeout for connecting to the URL. In milliseconds. Default is 10,000.
IntegerreadTimeoutThe read timeout for the get operation. In milliseconds. Default is 60,000.
StringusernameIf specified, the call will attempt to authenticate with basic HTTP authentication.
StringpasswordThe password used for basic HTTP authentication, if the username parameter is also present.
PyDictionaryheaderValues[Optional] A dictionary of name/value pairs that will be set in the HTTP header.
BooleanbypassCertValidation[Optional] 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.
BooleanuseCaches[Optional] 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.
BooleanthrowOnError[Optional] 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.

Returns

String - The content found at the given URL.

Scope

All

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

Code Examples

Code Snippet
# This code would return the source for Google's homepage
source = system.net.httpGet("http://www.google.com")
print source
Code Snippet
# This code would query Yahoo Weather for the temperature in Sacramento, CA
# and then find the current temperature using a regular expression

response = system.net.httpGet("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%3D2489314")

# import Python's regular expression library
import re

# NOTE - if you've never seen regular expressions before, don't worry, they look
# confusing even to people who use them frequently.
pattern = re.compile('.*?<yweather:condition (.*?)/>', re.DOTALL)
match = pattern.match(response)
if match:
subText = match.group(1)
condition = re.compile('.*?text="(.*?)"').match(subText).group(1)
temp = re.compile('.*?temp="(.*?)"').match(subText).group(1)
print "Condition: ", condition
print "Temperature (F): ", temp
else:
print 'Weather service format changed'