Created
November 23, 2014 12:41
-
-
Save jamessdixon/b346f45eb192cb9e05d3 to your computer and use it in GitHub Desktop.
Consuming IBM's Watson Language Translation Service Using F#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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