我正在尝试使用PlayFramework闪烁将JSON数据从ActionA
发送到ActionB
。这是代码:
路线:
POST /ActionA controllers.InstitutionController.ActionA
POST /ActionB controllers.GalleryController.ActionB
动作:
class InstitutionController extends Controller {
def ActionA = Action { implicit request =>
var jsonRequest = request.body.asJson.get
val uuid = (jsonRequest \ "uuid").as[String]
log.info("in ActionA" + uuid)
Redirect("/ActionB").flashing("uuid" -> uuid)
}
}
class GalleryController extends Controller {
def ActionB = Action { implicit request =>
val uuid = request.flash.get("uuid")
log.info("in ActionB " + uuid)
Ok("i am ActionB with id {}"+uuid)
}
}
这是
curl
文件:contentType="Content-type: application/json";
data='{ "uuid" : "123" }';
echo " "
echo "------------------ Sending Data ------------------"
echo " "
echo "Content-Type : " $contentType
echo "Data : " $data
echo " "
echo "------------------ Response ------------------"
echo " "
echo " "
和
curl
命令:curl --include --request POST --header "Content-type: application/json" --data "$data" http://localhost:9000/ActionA
预期的响应是“我是ID为123的ActionB”,但我得到了以下响应:
HTTP/1.1 303 See Other
Location: /ActionB
Date: Sun, 05 Mar 2017 08:59:29 GMT
Content-Length: 0
为什么我得到这个回应?为什么没有呼叫
ActionB
? 最佳答案
没错在Play Framework中使用Redirect
会生成303 http代码。
您必须使用-L
选项告诉curl遵循HTTP重定向:
curl -L --include --request POST --header "Content-type: application/json" --data "$data" http://localhost:9000/ActionA