[ad_1]
I am simply making an attempt to ship easy variable to server utilizing put up request and I wish to do it manually.
Right here is my code
guard let url = URL(string: urlString+"/someapi") else {
return
}
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue(String(3), forHTTPHeaderField:"Content material-Size")
request.setValue("software/x-www-form-urlencoded", forHTTPHeaderField: "Content material-Sort")
request.setValue("textual content/plain", forHTTPHeaderField: "Settle for")
var httpBody:Information=Information()
httpBody.append(contentsOf: "f=1".knowledge(utilizing: .utf8)!) //f is essential & 1 worth
request.httpBody = httpBody
let onComplete = {
(knowledge:Information?,urlresponse:URLResponse?,error:Error?)->Void in
//do nothing
if let _ = error {
print("Error occured")
}
}
let process = session.dataTask(with: url, completionHandler: onComplete)
process.resume()
I am utilizing flask server to check this out. On flask aspect I analysed the request right here is the it is header content material
Settle for: */*
Settle for-Language: en-US,en;q=0.9
Connection: keep-alive
Settle for-Encoding: gzip, deflate
Consumer-Agent: Findpercent20Doctor/1 CFNetwork/1333.0.4 Darwin/21.4.0
And in addition flask server is receiving GET request as an alternative of POST and in addition variables will not be exhibiting in server.
[ad_2]
