To form an HTTP[S] request you need to know:
URL — This is passed in when you construct the
URLRequest
value.HTTP method — This is set via the
httpMethod
property.Any special headers, like
Content-Type
— These are set via the setValue(_:forHTTPHeaderField:)
method.The body data — You can set this via the
httpBody
property, but it’s more normal to pass it in when you create the URLSessionUploadTask
.
For a JSON request you generally form the body data by construction the relevant native values and then serialising it to data using
JSONSerialization
.
Which of these things do you need help with?
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"