1
我知道有关于堆栈溢出的类似问题,但没有解决我的问题。 我做一个简单的NSMutableRequest到URL和发布一个简单的字符串:NSMutableURLRequest POST 405错误获取
let locationString = "myString"
let request = NSMutableURLRequest(URL: NSURL(string: "http://exampleurl.com")!)
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.HTTPMethod = "POST"
request.HTTPBody = locationString.dataUsingEncoding(NSUTF8StringEncoding)
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
data, response, error in
if error != nil {
print("error=\(error)")
return
}
print("response = \(response)")
let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
print("responseString = \(responseString)")
}
task.resume()
,但我得到一个405错误:“方法来获取不允许”
不知道我在做什么错
感谢
https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSJSONSerialization_Class/#//apple_ref/occ/clm/NSJSONSerialization/dataWithJSONObject:options:error –
谢谢@LeoDabus,但我不能使用NSJSONSerialization作为API调用需要按顺序发送键/值。我知道这是不对的,但我无法控制这一点。 – mrcurious
你能解释一下为什么我用当前的方法得到这个错误吗? – mrcurious