-H "Authorization: Bearer xxxxx-xxxx-xxxxxx-xxxxx" \-d text=こんにちは \-d source_lang=ja \-d target_lang=en>> ["Hello."]
let accessToken = "xxxxx-xxxx-xxxxxx-xxxxx"let url = URL(string: "https://sandbox-mt.mimi.fd.ai/machine_translation")var req = URLRequest(url: url!, cachePolicy: URLRequest.CachePolicy.useProtocolCachePolicy, timeoutInterval: 5)req.httpMethod = "POST"req.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization")req.setValue("application/x-www-form-urlencoded; charset=utf-8", forHTTPHeaderField: "Content-Type")req.httpBody = "text=こんにちわ&source_lang=ja&target_lang=en".data(using: utf8)
let task = URLSession.shared.dataTask(with: req) { (data, response, error) in print(String(data: data!, encoding: .utf8)!) // ["Good afternoon."]が出力される["Good afternoon."]
}
task.resume()・こんにちわ → Good afternoon.
・こんにちは → Hello.
ご確認ください。