有人可以解释 Ok 在游戏框架中的含义吗?
Can someone explain what Ok means in play framework?
我找到了文档 here but I do not understand what this class does. (I'm also new to scala coming from a java background so any explanation helps). Also what does "200 Ok" response mean as shown here
服务器接收 HTTP 请求消息,对其进行解释并使用 HTTP 响应消息进行响应。
这就是 Action
with Play 所做的,它接收请求消息并用响应消息进行响应。
响应消息的第一行是状态行。这可能是 OK
、BadRequest
、NotFound
等等。可以看到完整的状态码here.
那么,我们如何使用 Play 进行操作如下:
def a() = Action { request => // this `request` is optional
Ok("Here's your content")
// BadRequest("You're asking wrong")
// NotFound("You're asking for something we don't have")
// etc
}
Action
为我们的代码块提供 request
,我们可以用它来解释请求并产生响应。 Ok
行指定响应消息的状态代码为 OK
。然后参数中的其余响应等等 - 例如,使用 withHeaders
的附加响应 headers。 Play MVC
API 通常遵循这种模式。例如,Ok.sendFile(new File("myfile.txt"))
发送Ok
状态码,内容为文件。
我找到了文档 here but I do not understand what this class does. (I'm also new to scala coming from a java background so any explanation helps). Also what does "200 Ok" response mean as shown here
服务器接收 HTTP 请求消息,对其进行解释并使用 HTTP 响应消息进行响应。
这就是 Action
with Play 所做的,它接收请求消息并用响应消息进行响应。
响应消息的第一行是状态行。这可能是 OK
、BadRequest
、NotFound
等等。可以看到完整的状态码here.
那么,我们如何使用 Play 进行操作如下:
def a() = Action { request => // this `request` is optional
Ok("Here's your content")
// BadRequest("You're asking wrong")
// NotFound("You're asking for something we don't have")
// etc
}
Action
为我们的代码块提供 request
,我们可以用它来解释请求并产生响应。 Ok
行指定响应消息的状态代码为 OK
。然后参数中的其余响应等等 - 例如,使用 withHeaders
的附加响应 headers。 Play MVC
API 通常遵循这种模式。例如,Ok.sendFile(new File("myfile.txt"))
发送Ok
状态码,内容为文件。