Skip to content

Instantly share code, notes, and snippets.

@vialyx
Created March 30, 2020 14:28
Show Gist options
  • Save vialyx/4ae6480130f78075d9fb45ad7cd72e6b to your computer and use it in GitHub Desktop.
Save vialyx/4ae6480130f78075d9fb45ad7cd72e6b to your computer and use it in GitHub Desktop.
import UIKit
import PlaygroundSupport
let url = URL(string: "https://petstore.swagger.io/v2/user")!
var request = URLRequest(url: url)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("application/json", forHTTPHeaderField: "accept")
request.httpMethod = "POST"
request.httpBody = """
{
"id": 0,
"username": "string",
"firstName": "string",
"lastName": "string",
"email": "string",
"password": "string",
"phone": "string",
"userStatus": 0
}
""".data(using: .utf8)
URLSession.shared.dataTask(with: request) { (data, response, error) in
print("\(String(data: data ?? Data(), encoding: .utf8)) - \(response) - \(error)")
}.resume()
PlaygroundPage.current.needsIndefiniteExecution = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment