Introduction
Spotfire can call REST web services using IronPython. Here is an example of using a POST call over HTTPS with Authentication. This example was written to call an SMS gateway in order to send text messages to a mobile phone.
Code Sample
# Import the necessary packages import clr clr.AddReference('System.Web.Extensions') from System.Web.Script.Serialization import JavaScriptSerializer from System.Net import * from System import Convert from System.Text import Encoding import urllib # - this needs Python 2.7.7 or later! ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; #TLS 1.2 # Create a web client client = WebClient() username = "myusername" password = "mypassword" message = "Mr. Hotblack Desiato, lunch at Milliways is booked " \ "for 19th August, 87.5463245e120. Please deposit a penny in a " \ "savings account in preparation! See you in a few hundred era. " \ "Sincerely, Garkbit" credentials = Convert.ToBase64String( Encoding.ASCII.GetBytes(username + ":" + password)); client.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials; client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded" dict = { "Body" : message, "To" : "+447723 123456", "From" : "+447745 456789"} data = urllib.urlencode(dict) print data address = "https://myrestserviceprovider.com/endpoint"" print client.UploadString(address,data)
License: TIBCO BSD-Style License
Recommended Comments
There are no comments to display.