1
我正在向帶有HTML表單的服務器發送發佈請求。當我按下表單的提交按鈕時,我得到一個404頁面不存在的錯誤。但是,如果我通過直接在地址欄中輸入內容來訪問URL,則會發現我應該從服務器獲得的錯誤(400無效請求)。頁面存在時出現404錯誤
這裏是我的HTML(注意我用的葉):
#extend("base")
#export("head") {
<link rel="stylesheet" href="/styles/normalize.css">
<link rel="stylesheet" href="/styles/skeleton.css">
}
#export("body") {
<div class="container">
<form action="/admin/new-post" method="POST">
<div class="row" style="padding: 25px 0 0 0;">
<div class="six columns form-group">
<label for="email">Usernam</label>
<input class="u-full-width" type="text" placeholder="Username" id="email" name="email">
</div>
<div class="six columns form-group">
<label for="password">Password</label>
<input class="u-full-width" type="password" placeholder="Password" id="password" anem="password">
</div>
</div>
<input type="hidden" name="_csrf" value="{{csrfToken}}">
<button type="submit" class="button-primary">Login</button>
</form>
</div>
}
我的服務器代碼(SWIFT):
import Vapor
import HTTP
final class AdminController {
func addRoutes(to drop: Droplet) {
let admin = drop.grouped("admin")
drop.get("login", handler: login)
admin.get("new-post", handler: newPost)
}
func login(_ request: Request)throws -> ResponseRepresentable {
return try drop.view.make("admin-login", [])
}
func newPost(_ request: Request)throws -> ResponseRepresentable {
guard let cred = request.auth.header?.basic else {
throw Abort.badRequest
}
do {
try request.auth.login(cred)
return try drop.view.make("new-post", [])
} catch {
return Response(redirect: "/login?login=failed")
}
}
}
爲什麼我收到一個404錯誤?
我使用的Web框架是Vapor。