Quantcast
Channel: Microsoft Translator User Forum (Including Bing Translator) forum
Viewing all articles
Browse latest Browse all 529

Always receiving Bad Request response, even using microsoft sample...

$
0
0

Hi, I'm trying to use the Microsoft Translator API from Http

I found the sample code here : http://msdn.microsoft.com/en-us/library/ff512387.aspx

Here's my code: 

			string text = "Use pixels to express measurements for padding and margins.";
			string from = "en";
			string to = "de";
			string uri = "http://api.microsofttranslator.com/v2/Http.svc/Translate?text=" + WWW.EscapeURL(text) + "&from=" + from + "&to=" + to;

			HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);
			httpWebRequest.Headers.Add("Authorization", "Bearer " + token.access_token);
			Debug.Log(httpWebRequest.Headers);
			WebResponse response = null;
			try
			{
				response = httpWebRequest.GetResponse();
				using (Stream stream = response.GetResponseStream())
				{
					System.Runtime.Serialization.DataContractSerializer dcs = new System.Runtime.Serialization.DataContractSerializer(Type.GetType("System.String"));
					string translation = (string)dcs.ReadObject(stream);
					Debug.Log(String.Format("Translation for source text '{0}' from {1} to {2} is", text, "en", "de"));
					Debug.Log(translation);
				}
			}
			catch (System.Exception e)
			{
				Debug.Log ("SimpleTranslate: " + e.Message);
				throw e;
			}

I always get the exception : The remote server returned an error: (400) Bad Request.

I don't understand why it is not working, it's a really simple sample... or is it a deprecated functionnality??


Viewing all articles
Browse latest Browse all 529

Trending Articles