制作swift PATCH请求时出错400

时间:2016-07-10 18:38:02

标签: ios swift

 @IBAction func postSoS(sender: AnyObject) {
    postSos()
}

func postSos() {

    let headers = [
        "cache-control": "no-cache",
        "postman-token": "token here -- taken out --"
    ]

    print("button pressed")
    let url: NSURL = NSURL(string: "site here -- taken out")!
    let request:NSMutableURLRequest = NSMutableURLRequest(URL: url)
    let postData = "Status=1"
    request.HTTPMethod = "PATCH"
    request.allHTTPHeaderFields = headers
    request.HTTPBody = postData.dataUsingEncoding(NSUTF8StringEncoding)





    let session = NSURLSession.sharedSession()
    let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
        if (error != nil) {
            print(error)
        } else {
            let httpResponse = response as? NSHTTPURLResponse
            print(httpResponse)
        }
    })

    dataTask.resume()


}

所以我的问题是这个错误代码返回400错误代码,我认为这是一个错误的请求。该程序的目标是让用户按下按钮,然后在网站上更改颜色。使用postData =“Status = 1”还有其他状态代码但是1是我的例子。状态是我必须改变的价值。有什么想法吗?

0 个答案:

没有答案