小编Kei*_*Kei的帖子

Swift 4 Decodable:给定数据无效JSON

我正在尝试向我的本地服务器写一个POST请求,这是我的功能:

@IBAction func postButtonAction(_ sender: UIButton) {

    guard let url = URL(string:"http://localhost:443/api/message") else {return}
    var request = URLRequest(url: url)
    request.httpMethod = "POST"
    request.addValue("application/json", forHTTPHeaderField: "Content-Type")
    print("POSTED")

    let date : Date = Date()
    let dateFormatter = DateFormatter()
    dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
    let dateTime = dateFormatter.string(from: date)

    let newPost = MessageForPost(message: "Hi", timestamp: dateTime, latitude: "1.1", longitude: "2.2")
    let newData = DataForPost(message: newPost)
    let newPackage = PackageForPost(data: newData)

    do {
        let jsonBody = try JSONEncoder().encode(newPackage)
        request.httpBody = jsonBody
        print("jsonBody:",jsonBody)
        let jsonBodyString = …
Run Code Online (Sandbox Code Playgroud)

json ios swift codable decodable

9
推荐指数
1
解决办法
9922
查看次数

如何在 Heroku 上显示 console.log()?

我尝试通过在 Node.js 中使用 console.log() 来调试我的应用程序。

但是,无论它们显示多少行,我都永远无法在 heroku 日志中看到它们。

$ heroku logs -n 200
Run Code Online (Sandbox Code Playgroud)

这对我不起作用。

每当我在 Heroku 服务器上发布内容时,日志只显示如下内容:

2018-09-10T02:14:12.731148+00:00 heroku[router]: at=info method=POST path="/users" host=obscure-journey-65698.herokuapp.com request_id=349a44e8-5fd7-46a2-aacb-75e51503109c fwd="73.67.204.217" dyno=web.1 connect=1ms service=355ms status=400 bytes=216 protocol=https
Run Code Online (Sandbox Code Playgroud)

控制台日志永远不会显示!他们在运行 npm start 时确实记录了我想要的信息。

谢谢你的帮助。

javascript heroku node.js heroku-toolbelt console.log

5
推荐指数
1
解决办法
5976
查看次数