I am building an application in Flash that exchanges messages between itself and the server in the form of JSON objects.
My AS3 code :
var person:Object = new Object();
person.firstname = "A";
person.lastname = "B";
var url:String = "http://localhost:9000/Ithaca";
var request:URLRequest = new URLRequest(url);
request.method = URLRequestMethod.POST;
var requestVars:URLVariables = new URLVariables();
requestVars.myObject = JSON.stringify(person);
request.data = requestVars;
var loader:URLLoader = new URLLoader();
loader.load(request);The routes file:
POST /Ithaca controllers.Application.ithacaThe Application.scala file:
package controllers
import play.api.libs.json._
import play.api.mvc._
import org.codehaus.jackson.JsonNode
import org.codehaus.jackson.node.ObjectNode
object Application extends Controller
{
def ithaca = Action(parse.json) { request =>
(request.body \ "firstname").asOpt[String].map { name =>
Ok("JSON received")
}.getOrElse {
BadRequest("Bad Request. Try again")
}
}}But, upon running the Flash application, I am getting this error
Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL:http://localhost:9000/IthacaCan somebody guide me how to send POST requests to the Play Framework? (P.S : The AS3 code works fine when I was using a PHP script to parse the JSON earlier)
--
Logger.info(request.body.toString())
curl --header "Content-type: application/json" --request POST --data '{"firstname": "A", "lastname" : "B"}' http://localhost:9000/Ithaca--
| can you add the contentype before sending the request ? using : request.contentType = "application/json"; or : var hdr:URLRequestHeader = new URLRequestHeader("Content-type", "application/json"); request.requestHeaders.push(hdr); |
--