Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- let headers = [
- "x-rapidapi-host": "google-translate1.p.rapidapi.com",
- "x-rapidapi-key": "78767832e6mshd1b6d5b2fa681a2p1229e3jsn09a1a1972cad",
- "accept-encoding": "application/gzip",
- "content-type": "application/x-www-form-urlencoded"
- ]
- let postData = NSMutableData(data: "source=en".data(using: String.Encoding.utf8)!)
- postData.append("&q=Hello, world!".data(using: String.Encoding.utf8)!)
- postData.append("&target=es".data(using: String.Encoding.utf8)!)
- let request = NSMutableURLRequest(url: NSURL(string: "https://google-translate1.p.rapidapi.com/language/translate/v2")! as URL,
- cachePolicy: .useProtocolCachePolicy,
- timeoutInterval: 10.0)
- request.httpMethod = "POST"
- request.allHTTPHeaderFields = headers
- request.httpBody = postData as Data
- let session = URLSession.shared
- let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
- if (error != nil) {
- print(error)
- } else {
- let httpResponse = response as? HTTPURLResponse
- print(httpResponse)
- }
- })
- dataTask.resume()
Add Comment
Please, Sign In to add comment