我正在尝试通过 Plivo SMS API 发送短信。不幸的是,即使请求 HTTP 方法是“POST”,该请求还是发布为“GET”。请在下面查看我的代码。
let fromNumber = "11111111111"
let toNumber = "111111234"
let message = "Hello"
do {
let json = ["src":"\(fromNumber)","dst":"\(toNumber)","text":"\(message)"]
let jsonData = try NSJSONSerialization.dataWithJSONObject(json, options: NSJSONWritingOptions.PrettyPrinted)
print(jsonData)
// Build the request
let request = NSMutableURLRequest(URL: NSURL(string:"https://"\(authId)":"\(authToken)"@api.plivo.com/v1/Account/"\(authId)"/Message")!)
// I'm assigning the method should be 'POST' but why its going as 'GET'
request.HTTPMethod = "POST"
request.HTTPBody = jsonData
// Build the completion block and send the request
let task = NSURLSession.sharedSession().dataTaskWithRequest(request){ data, response, error in
if error != nil{
print("Error -> \(error)")
return
}
do {
let result = try NSJSONSerialization.JSONObjectWithData(data!, options: []) as? [String:AnyObject]
print("Result -> \(result)")
} catch {
print("Error -> \(error)")
}
}
task.resume()
//return task
} catch {
print(error)
}
}