파일 업로드 중, 서버에서 XML 응답을 받고 싶습니다.AS3 : DataEvent.data를 XML로 변환 할 수 없습니다 (형식이 잘못됨, 오류 발생)
그래서, PHP에서, 내가 할 : 플래시에서
header("Content-type:text/xml");
echo"<whatever/>"; // any 100% valid XML
, 내가 FileReference
클래스와 DataEvent.data
구문 분석 할 수없는 보이지 않는 쓰레기를 포함처럼
var file:FileReference = new FileReference();
file.addEventListener(Event.SELECT, FileSelected);
file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, uploaded);
...
function FileSelected(e:Event)
{
var req:URLRequest=new URLRequest(Main.baseURL+"/upload.php");
req.method="POST";
try{file.upload(req,"userfile")}
catch(err:Error){Main.err("Can't upload",err,e)}
}
function uploaded(e:DataEvent)
{
var s:String=e.data;
trace(":"+s+":"); //output :<whatever/>: as expected
var xml:XML=new XML(s); // fails with Error #1088: The markup in the document following the root element must be well-formed.
}
이 보인다 FileReference.upload()
방법을 사용 .. 현재 해결 방법은 첫 번째 문자 (0xFEFF)를 수동으로 잘라내는 것입니다.
function uploaded(e:DataEvent)
{
var s:String=e.data.slice(1); // if i manually cut it off - all works
trace(s);
var xml:XML=new XML(s);
}
여분의 것이 있는지'trace (":"+ s + ":");'를 수행하십시오. – Amarghosh
첫 번째 문자로 0xFEFF가 포함되어 있습니다. 내가 수동으로 그것을 자르면, 모든 작품,하지만 난 _good_ 솔루션이 아닌 것 같아요 – joox
소켓 클래스를 사용하고 계십니까? – Amarghosh