Skip to content

Instantly share code, notes, and snippets.

@jamessdixon
Created November 23, 2014 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamessdixon/b346f45eb192cb9e05d3 to your computer and use it in GitHub Desktop.
Save jamessdixon/b346f45eb192cb9e05d3 to your computer and use it in GitHub Desktop.
Consuming IBM's Watson Language Translation Service Using F#
//Make sure you install WebApi.Client via Nuget
//install-package Microsoft.AspNet.WebApi.Client
#r @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Net.Http.dll"
#r @"..\packages\Microsoft.AspNet.WebApi.Client.5.2.2\lib\net45\System.Net.Http.Formatting.dll"
open System
open System.Net.Http
open System.Net.Http.Headers
open System.Net.Http.Formatting
open System.Collections.Generic
let serviceName = "machine_translation"
let baseUrl = "http://wex-mt.mybluemix.net/resources/translate"
let userName = "yourName@aol.com"
let password = "yourCreds"
let authKey = userName + ":" + password
let client = new HttpClient()
client.DefaultRequestHeaders.Authorization <- new AuthenticationHeaderValue("Basic",authKey)
let input = new Dictionary<string,string>()
input.Add("text","This is a test")
input.Add("sid","mt-enus-eses")
let content = new FormUrlEncodedContent(input)
let result = client.PostAsync(baseUrl,content).Result
let resultContent = result.Content.ReadAsStringAsync().Result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment