1

Good evening. I'm trying to create a simple translator for IOS. I'd like to use YandexTranslator API which requires the following request:

https://translate.yandex.net/api/v1.5/tr.json/translate ? 
key=<API key>
 & text=<text to translate>
 & lang=<translation direction>
 & [format=<text format>]
 & [options=<translation options>]
 & [callback=<name of the callback function>]

I'm using Alamofire and my code and my request look like the following:

 @IBAction func translateButtonPressed(_ sender: Any) {
        var newWord = wordField.text

    Alamofire.request("https://translate.yandex.net/api/v1.5/tr.json/translate?lang=en-ru&text=\(newWord))&key=*hereGoesMyKey*", method: .post).responseJSON { response in
        if let translatedWord = response.result.value{
            print(translatedWord)
        }

And my problem is that nothing happens, my JSON data is empty. Could you give me some clue how to fix my problem?

1 Answers1

0

The problem was in my request. The correct request is

Alamofire.request("https://translate.yandex.net/api/v1.5/tr/translate?lang=en-ru&key=trnsl.1.1.20171121T074309Z.544897eeddde0767.1f5294097895427b85c7aa3eca7262c17286edd8", method: .post, parameters: ["text" : wordField.text!] ).responseData { response in ...