Skip to content

Instantly share code, notes, and snippets.

@lotusirous
Created March 4, 2022 06:39
Show Gist options
  • Save lotusirous/571653b6732c5d3bbfac829f884dd2d0 to your computer and use it in GitHub Desktop.
Save lotusirous/571653b6732c5d3bbfac829f884dd2d0 to your computer and use it in GitHub Desktop.
import UIKit
let url = URL(string: "http://127.0.0.1:1234")!
var request = URLRequest(url: url)
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("you-value-goes-here", forHTTPHeaderField: "X-API-KEY")
let task = URLSession.shared.dataTask(with: request) { data, _, error in
if let data = data {
print(data)
} else if let error = error {
print("Http failed: \(error)")
}
}
task.resume()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment