Created
March 30, 2020 14:28
-
-
Save vialyx/4ae6480130f78075d9fb45ad7cd72e6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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