gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 14:10:36 26 4
gpt4 key购买 nike

我从来没有接触过编程,但最近为了一个学校项目(我正在学习工业设计,所以我没有软件背景)我试图将此代码移植到一个基本的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com