如何在Amazon Web Services中快速发布数据?

编程入门 行业动态 更新时间:2024-10-26 10:35:55
本文介绍了如何在Amazon Web Services中快速发布数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用此代码迅速将数据发布到"Amazon Web Services"中.

I used this code to post data in "Amazon Web Services" in swift.

let userNameData = String("prnty").dataUsingEncoding(NSASCIIStringEncoding)! let passData = String("xxx").dataUsingEncoding(NSASCIIStringEncoding)! let tokenData = String("xxxxxx").dataUsingEncoding(NSASCIIStringEncoding)! let deviceTypeData = String("ios").dataUsingEncoding(NSASCIIStringEncoding)! Alamofire.upload( .POST, "xxxxx.execute-api.ap-southeast-1.amazonaws/dev/webserv", headers:["x-api-key":"xxxxxxxxx"], multipartFormData: { multipartFormData in multipartFormData.appendBodyPart(data: userNameData, name: "username") multipartFormData.appendBodyPart(data: passData, name: "password") multipartFormData.appendBodyPart(data: tokenData, name: "token") multipartFormData.appendBodyPart(data: deviceTypeData, name: "deviceType") }, encodingCompletion: { encodingResult in switch encodingResult { case .Success(let upload, _, _): upload.responseJSON { response in print(response) } case .Failure(let encodingError): print(encodingError) } } )

我能够成功通过AWS服务器进行身份验证.似乎数据无法继续我的server.OKClient在Android中正常工作 不获取帖子数据(对于iOS,获取零个POST数据)* 可能是什么错误?

i am able to authenticate with AWS server successfully but. seems to data is not going further my server.it works fine in Android by OKClient not getting post data (getting nil POST data for iOS)* what could be the error?

推荐答案

如果您的服务器希望接收application/json,则可以很好地进行以下操作:

If your server expect to receive application/json, the following works well:

let headers = ["x-api-key": "xxxxxxxxx"] let parameters = [ "userNameData": "prnty", "passData": "xxx", "tokenData": "xxxxxx", "deviceTypeData": "ios" ] Alamofire.request(.POST, "xxxxx.execute-api.ap-southeast-1.amazonaws/dev/webserv", headers: headers, parameters: parameters, encoding: .JSON) .responseJSON { response in print(response.request) // original URL request print(response.response) // URL response print(response.data) // server data print(response.result) // result of response serialization if let JSON = response.result.value { print("JSON: \(JSON)") } }

如果不是,则无需使用encoding参数.

if not, you don't need to use the encoding parameter.

更多推荐

如何在Amazon Web Services中快速发布数据?

本文发布于:2023-10-12 00:17:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483246.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:快速   数据   如何在   Web   Amazon

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!