当我将数据发布到服务器时,我遇到了问题,它似乎根本不起作用..我发现了另一个用于发布的代码
这是post的代码
func post(params : Dictionary<String, String>, url : String, postCompleted : (succeeded: Bool, msg: String) -> ()) {
var request = NSMutableURLRequest(URL: NSURL(string: "")!)
var session = NSURLSession.sharedSession()
request.HTTPMethod = "POST"
// let postString = "Body: \(personaldata.data)"
var err: NSError?
// request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
request.HTTPBody = NSJSONSerialization.dataWithJSONObject(params, options: nil, error: &err)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("application/json", forHTTPHeaderField: "Accept")
var task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in
println("Response: \(response)")
var strData = NSString(CString: personaldata.data, encoding: NSUTF8StringEncoding)
println("Body: \(personaldata.data)")
var err: NSError?
var json = NSJSONSerialization.JSONObjectWithData(data, options: .MutableLeaves, error: &err) as? NSDictionary
var msg = "No message"
})
task.resume()
}
当按下发送按钮时,这里是代码
func tapGesture(gesture: UIGestureRecognizer) {
self.performSegueWithIdentifier("analisa", sender: self)
if let Kirim = gesture.view as? UIImageView { // if you subclass UIImageView, then change "UIImageView" to your subclass
self.post(["ID":"123", "function_name":"update_db", "personal_information_table":"\(personaldata.data)"], url: "") { (succeeded: Bool, msg: String) -> () in
}
}
}
println正确输出时的输出,但它没有出现在网站上,怎么可能?
我隐藏了网站地址(它只显示包含id和weight的行,包含在(personaldata.data)中的高度 我的朋友谁在Android上工作,已成功发送数据:/
这是网站,这是我的朋友数据,而不是我的
是我的代码错误还是什么?
这是println
Response: <NSHTTPURLResponse: 0x7fe591554d60> { URL: } { status code: 500, headers {
"Accept-Ranges" = none;
"Cache-Control" = private;
"Content-Type" = "text/plain; charset=UTF-8";
Date = "Fri, 28 Aug 2015 09:34:02 GMT";
Server = "Google Frontend";
Vary = "Accept-Encoding";
"alt-svc" = "quic=\":443\"; p=\"1\"; ma=604800";
} }
Body: {"height": 214, "weight": 123}
答案 0 :(得分:0)
状态码:500表示只能通过修复Web服务器软件来解决错误。这不是客户端问题。由Web服务器站点的操作员来定位和分析日志,这些日志应提供有关错误的更多信息。