Actionscript 3 在as3 AIR中发出HTTP POST请求

Actionscript 3 在as3 AIR中发出HTTP POST请求,actionscript-3,air,httprequest,Actionscript 3,Air,Httprequest,我正在尝试通过as3 AIR for mobile发出HTTP POST请求,该请求与此curl请求等效: curl -d '{"firstname": "John", "lastname": “Doe"}' -H 'Content-Type: application/json' http://eve-demo.herokuapp.com/people 这是我的代码: var urlVariables:URLVariables = new URLVariables(); urlVariable

我正在尝试通过as3 AIR for mobile发出HTTP POST请求,该请求与此curl请求等效:

curl -d '{"firstname": "John", "lastname": “Doe"}' -H 'Content-Type: application/json' http://eve-demo.herokuapp.com/people
这是我的代码:

var urlVariables:URLVariables = new URLVariables();
urlVariables.firstname = "Jhon";
urlVariables.lastname = "Doe";

var request:URLRequest = new URLRequest();
request.url = "http://eve-demo.herokuapp.com/people";
request.contentType = "multipart/form-data";
request.method = URLRequestMethod.POST;
request.data = urlVariables;

var contentTypeHeader:URLRequestHeader = new URLRequestHeader("Content-Type", "application/json");
var acceptHeader:URLRequestHeader = new URLRequestHeader("Accept", "application/json");
var formDataHeader:URLRequestHeader = new URLRequestHeader("Content-Type", "multipart/form-data");

request.requestHeaders = [acceptHeader, formDataHeader];

postLoader = new URLLoader();
postLoader.dataFormat = URLLoaderDataFormat.BINARY;
postLoader.addEventListener(Event.COMPLETE, loaderCompleteHandler);
postLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
postLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
postLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

try
{
    postLoader.load(request);
}
catch (error:Error)
{
    trace("Unable to load post URL");
}
但我得到了以下错误:

[HTTPStatusHandler]: [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=400 redirected=false responseURL=null]
[IOErrorHandler]: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://eve-demo.herokuapp.com/people" errorID=2032]
有人对如何使用“多种格式/表单数据”(无需上传任何文件)发出http post请求有什么建议吗


谢谢

URLVariables
用于url编码的变量,而不是JSON。尝试将
数据设置为JSON字符串:

var params:Object = { firstname: "John", lastname: "Doe" };
request.data = JSON.stringify(params);

检查答案如果我想上传文件,这可能有效,但如果我只想将这两个变量作为POST请求发送,该怎么办?只需跳过byteArray,它可以为空,或者如果您不需要contentType=“multipart/form data”,您也可以跳过它进行设置(默认值为“application/x-www-form-urlencoded”)现在http状态错误代码是422!!!不,我还是不工作。。HTTP状态为400时出现相同错误您确定参数对该web服务有效吗?是的,该服务是python eve框架的演示,您也可以使用它!!好啊我这样问是因为我试过了,发现如果省略参数,数据就会返回。相关文档在哪里?这里:我对RESTAPI和HTTP请求的内容没有多大帮助,因为我对这方面还不熟悉。。!