html - 使用 swift 进行 HTTP 发布。基本物联网应用程序

标签 html ios swift post iot

我从来没有接触过编程,但最近为了一个学校项目(我正在学习工业设计,所以我没有软件背景)我试图将此代码移植到一个基本的 iOs 应用程序中。只是 POST 操作,而不是格式。

center><br>
<br>
<br>
<form action="https://api.particle.io/v1/devices/your-device-ID-goes-here/led?access_token=your-access-token-goes-here" method="POST">
Tell your device what to do!<br>
<br>
<input type="radio" name="args" value="on">Turn the LED on.
<br>
<input type="radio" name="args" value="off">Turn the LED off.
<br>
<br>
<input type="submit" value="Do it!">
</form>
</center>

这就是我所拥有的,但现在是我。

import UIKit

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.


        let myUrl = NSURL(string: "https://api.particle.io/v1/devices/your-device-ID-goes-here/led?access_token=your-access-token-goes-here")
        let request = NSMutableURLRequest (URL:myUrl!)
        request.HTTPMethod = "POST"







    }

最佳答案

希望能为您看到这个“框架”

https://github.com/daltoniam/SwiftHTTP

如果您发帖,缺少参数... 它必须看到这个。

let request = NSMutableURLRequest(URL: NSURL(string: "http://www.thisismylink.com/postName.php"))
request.HTTPMethod = "POST"
let postString = "id=13&name=Jack"
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
data, response, error in

if error != nil {
    println("error=\(error)")
    return
}

println("response = \(response)")

let responseString = NSString(data: data, encoding: NSUTF8StringEncoding)
println("responseString = \(responseString)")
}
task.resume()

关于html - 使用 swift 进行 HTTP 发布。基本物联网应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31820282/

相关文章:

ios - 测试飞行 2.0.0 : "MyApp" isn't compatible with this device

ios - 如何使用 Swift 从其父级的 Nib 创建 View

swift - 在 Swift 中你能捕获 "fatal error unexpectedly found nil while unwrapping an optional value"吗?

ios - UITable 的内存问题

jquery - 删除最后一个Li后调整菜单

html - 将 div 扩展到页面高度减去像素的 100%

ios - Facebook Paper - 如何向上滑动缩放底部的 UIScrollView

html - 使用 svg 图像时 div 内留有空间

html - 图片上传到主机后不显示

ios - iOS 键盘下的空白区域