加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Swift – 使用HTML的蒸汽

发布时间:2020-12-14 02:25:37 所属栏目:百科 来源:网络整理
导读:我最近从 Perfect切换到 Vapor.In Perfect你可以做这样的事情而不使用html文件. routes.add(method: .get,uri: "/",handler: { request,response in response.setHeader(.contentType,value: "text/html") response.appendBody(string: "htmlimg src=http://
我最近从 Perfect切换到 Vapor.In Perfect你可以做这样的事情而不使用html文件.
routes.add(method: .get,uri: "/",handler: {
    request,response in
    response.setHeader(.contentType,value: "text/html")
    response.appendBody(string: "<html><img src=http://www.w3schools.com/html/pic_mountain.jpg></html>")
    response.completed()
   }
)

在Vapor中我发现返回html的唯一方法就是这样做.如何在不使用蒸汽中的html文件的情况下返回html代码?

drop.get("/") { request in
    return try drop.view.make("somehtmlfile.html")
}
您可以构建自己的 Response,完全避免视图.
drop.get { req in
  return Response(status: .ok,headers: ["Content-Type": "text/html"],body: "<html><img src=http://www.w3schools.com/html/pic_mountain.jpg></html>")
}

要么

drop.get { req in
  let response = Response(status: .ok,body: "<html><img src=http://www.w3schools.com/html/pic_mountain.jpg></html>")
  response.headers["Content-Type"] = "text/html"
  return response
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读