Hi All,
I am getting the error "the remote server returned an error: (400) Bad Request" while trying to make a translation request. Can anyone provide the possible reasons for the error?
Your help is greatly appreciated.
Regards,
Venu
Hi Joao,
Thanks for your reply. Please see below the .NET code that is making google translation call by passing chinse characters:
private string uri = "https://www.googleapis.com/language/translate/v2
private String messageFormat = "key={0}&q={1}&source={2}&target={3}";
public override string processResponse(String output, String message, string fromLanguage, string toLanguage)
{
object result = JsonResponse.Deserialize(output);
//return JsonResponse.HtmlDecode(((Response<TranslatedText>)result).responseData.translatedText);
return JsonResponse.HtmlDecode(((Response)result).Data.Translations[0].TranslatedText.ToString());
}
The above function returns the JSON response with the English translation. The following is JSONResponse class:
public class JsonResponse
{
public static object Deserialize(string Text)
{
Response myResult;
MemoryStream ms = null;
try
{
myResult =
new Response();
ms = new MemoryStream(Encoding.Unicode.GetBytes(Text));
DataContractJsonSerializer serializer = new DataContractJsonSerializer(myResult.GetType());
myResult = serializer.ReadObject(ms) as Response;
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (ms != null)
ms.Close();
}
return myResult;
}
public static string HtmlEncode(string text)
{
return System.Web.HttpUtility.HtmlEncode(text);
}
public static string HtmlDecode(string text)
{
return System.Web.HttpUtility.HtmlDecode(text);
}
}
The above code is not working at the client site. The client has proxy server configured and the firewall rules have been set to accept only IP addresses and the names. The code was working with version 1 of Google translation API. the client had configured the firewall to accept the IP address 74.125.71.95 for Google. Can you please let me know the IP address or range of IP addresses for Google that I can provide the client?
The project Id for the client is 746355742018. Please let me know if you need anything.
Would appreciate your early response.
Thanks
Venu