public async Task<string> accountLockUnlock(string wordtobeConverted)
{
try
{
var translatedText = "";
while (true)
{
translatedText = await Translate(wordtobeConverted, "en");
return translatedText;
}
}
catch (Exception ex)
{
//CreateConsentsResponse consents = new CreateConsentsResponse();
//consents.id = ex.Message.ToString();
//return consents;
throw new Exception(ex.Message.ToString());
}
}
public static async Task<string> Translate(string text, string language)
{
var encodedText = WebUtility.UrlEncode(text);
var uri = "https://api.microsofttranslator.com/V2/Http.svc/Translate?" +
$"to={language}&text={encodedText}";
var result = await client.GetStringAsync(uri);
return XElement.Parse(result).Value;
}
private const string key = "Key";
private static readonly HttpClient client = new HttpClient
{
DefaultRequestHeaders = { { "Ocp-Apim-Subscription-Key", key } }
};
After Hosting if try to call from PostMan, am getting Proper Result Sample Calling : azurewebsites.net/.../Ciao Result we are getting as "HELLO", So no issue till here
If i try calling the same URL azurewebsites.net/.../Ciao from Ajax call am getting " Response to preflight request doesn't pass access control check: It does not have HTTP ok status"
My Ajax Call:
var settings = { "async": true, "crossDomain": true, "url": "azurewebsites.net/.../Ciao", "method": "GET", "headers": { "cache-control": "no-cache", "Access-Control-Allow-Headers": "*" }}$.ajax(settings).done(function (response){console.log(response); });
Could any one help me here?