XCODE send XML request
#XCODE send XML request#
create XML body
```
let xmlRequest = "\(accessToken) \(userID) \(userPW) "
```
create url for XML request
```
let url = URL(string: "url")
var request = URLRequest(url: url!)
request.httpMethod = "POST"
request.addValue("application/XML", forHTTPHeaderField: "Content-Type")
let httpBodys = xmlRequest.data(using: String.Encoding.utf8)
request.httpBody = httpBodys
let session = URLSession.shared
session.dataTask(with: request) { (data, response, error) in
if let response = response {
print("response")
print(response)
}
if let data = data {
print("data")
//print(data)
}
}.resume()
```
Full Code :
```
let xmlRequest = "XML body"
let url = URL(string: "url")
var request = URLRequest(url: url!)
request.httpMethod = "POST"
request.addValue("application/XML", forHTTPHeaderField: "Content-Type")
let httpBodys = xmlRequest.data(using: String.Encoding.utf8)
request.httpBody = httpBodys
let session = URLSession.shared
session.dataTask(with: request) { (data, response, error) in
if let response = response {
print("response")
print(response)
}
if let data = data {
print("data")
//print(data)
}
}.resume()
```
留言
張貼留言