我需要将 ByteArray 从 Flex 发送到 Spring MVC servlet,但它不起作用。我录制了一个音频样本,在 AS3 中转换为 bytearray 并发送到 SpringMVC servlet,但接收 Java 的数据为空。
AS3 代码:
var flacCodec:Object;
flacCodec = (new cmodule.flac.CLibInit).init();
bytes.position = 0;
var rawData: ByteArray = new ByteArray();
var flacData : ByteArray = new ByteArray();
rawData = convert32to16(bytes);
flacData.endian = Endian.LITTLE_ENDIAN;
flacCodec.encode( encodingCompleteHandler,
encodingProgressHandler,
rawData,
flacData,
rawData.length,
30);
function encodingCompleteHandler(event:*):void {
var PATH:String = "http://localhost:8080/myproject/speechRecognition/";
var urlRequest:URLRequest = new URLRequest(PATH);
var urlLoader:URLLoader = new URLLoader();
urlRequest.contentType = "audio/x-flac; rate=44000";
var variables:URLVariables = new URLVariables();
variables.contents = flacData;
variables.filename = "test";
urlRequest.data = variables;
urlRequest.method = URLRequestMethod.POST;
urlLoader.dataFormat = URLLoaderDataFormat.TEXT; // default
urlLoader.addEventListener(Event.COMPLETE, urlLoader_complete);
urlLoader.addEventListener(ErrorEvent.ERROR, urlLoader_error);
urlLoader.load(urlRequest);
JAVA代码:
@RequestMapping(value = "/",method = RequestMethod.POST)
public String getSpeechRecognition(ServletRequest req) {
String filename = req.getParameter("filename");
byte[] contents = req.getParameter("contents").getBytes();
request= new SpeechRecognitionRequestVO();
request.setData(contents);
try {
response=((SpeechRecognitionResponseVO) getSpeechRecognitionService().getSpeechRecognition(request));
} catch (Exception e){
logger.error(e.toString());
}
return "views/sequence";
}
我在此参数中收到 null :
req.getParameter("contents")
有人知道发生了什么吗?