Titanium XHR - 在XHR.SEND期间解析XML时出错,同时故意不使用XML解析器

时间:2016-05-18 13:10:10

标签: android xml xmlhttprequest titanium saxparseexception

我正在尝试将照片从Titanium Appcelerator移动应用程序发送到网络服务器。

我使用以下示例:

var upload_token = "hi! I am a token!";

var content = '';
var boundary = '---------------------------170062046428149';

content += '--'+ boundary + '\r\n';
content += 'Content-Disposition: form-data; name="uploadToken"\r\n';
content += '\r\n';
content += upload_token + '\r\n';
content += '--'+ boundary + '\r\n';
content += 'Content-Disposition: form-data; name="myNickname"\r\n';
content += '\r\n';
content += myNickname+'\r\n';
content += '--'+ boundary + '\r\n';

content += 'Content-Disposition: form-data; name="nativePath"\r\n';
content += '\r\n';
content += 'file:///storage/emulated/0/Pictures/app-name/tia-217296905.jpg\r\n';
content += '--'+ boundary + '\r\n';

content += 'Content-Disposition: form-data; name="fileContent"; filename="/appicon.png"\r\n';
content += 'Content-Type: binary/octet-stream\r\n';
content += '\r\n';

var file = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, '/appicon.png');
var full_content = Ti.createBuffer({value: content});
var fileStream = Ti.Stream.createStream({ source : file.read(), mode : Titanium.Stream.MODE_READ});
var content_size = full_content.append(Ti.Stream.readAll(fileStream));
Ti.API.debug('Appended File Size : ' + content_size ); // ==> same as file.size

content = '\r\n';
content += '--'+ boundary + '--\r\n';
full_content.append(Ti.createBuffer({value : content}));

xhr = Ti.Network.createHTTPClient();
var send_data = full_content.toBlob();

var url = 'http://website.address/api/push_photo.php';
xhr.onload = function(e){
    console.log(e);
    alert("DONE!");
};
xhr.onerror = function(e){
    console.log(e);
};
xhr.open('POST', url);
xhr.setRequestHeader('Content-Type', 'multipart/form-data; boundary=' + boundary);
xhr.send({image:send_data});

一切按预期工作,文件传输到服务器,手机中的Titanium应用程序说" DONE!"。这意味着xhr.onload已被触发......

我的问题是关于我在开发者控制台中可以看到的错误:

  

[ERROR]:XMLModule:(KrollRuntimeThread)[13440,13649]解析时出错   XML [错误]:XMLModule:org.xml.sax.SAXParseException:意外   token(position:TEXT Array [ERROR]:XMLModule:([ERROR]:   XMLModule:[upl ... java.io.InputStreamReader@42917730中的@ 7:1)   [错误]:XMLModule:at   org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:146)   [错误]:XMLModule:at   javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:107)   [错误]:XMLModule:at   ti.modules.titanium.xml.XMLModule.parse(XMLModule.java:82)[错误]:   XMLModule:at   ti.modules.titanium.xml.XMLModule.parse(XMLModule.java:68)[错误]:   XMLModule:at   ti.modules.titanium.network.TiHTTPClient.getResponseXML(TiHTTPClient.java:562)   [错误]:XMLModule:at   ti.modules.titanium.network.HTTPClientProxy.getResponseXML(HTTPClientProxy.java:129)   [错误]:XMLModule:at   org.appcelerator.kroll.runtime.v8.V8Object.nativeCallProperty(母语   方法)[错误]:XMLModule:at   org.appcelerator.kroll.runtime.v8.V8Object.callProperty(V8Object.java:73)   [错误]:XMLModule:at   org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1155)   [错误]:XMLModule:at   android.os.Handler.dispatchMessage(Handler.java:95)[错误]:   XMLModule:在android.os.Looper.loop(Looper.java:137)[错误]:   XMLModule:at   org.appcelerator.kroll.KrollRuntime $ KrollRuntimeThread.run(KrollRuntime.java:118)   [错误]:TiHTTPClient:(KrollRuntimeThread)[7,13656]解析错误   XML [错误]:TiHTTPClient:org.xml.sax.SAXParseException:意外   token(position:TEXT Array [ERROR]:TiHTTPClient:([ERROR]:   TiHTTPClient:[upl ... @ java :io.InputStreamReader@42917730中的@ 7:1)   [错误]:TiHTTPClient:at   org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:146)   [错误]:TiHTTPClient:at   javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:107)   [错误]:TiHTTPClient:at   ti.modules.titanium.xml.XMLModule.parse(XMLModule.java:82)[错误]:   TiHTTPClient:at   ti.modules.titanium.xml.XMLModule.parse(XMLModule.java:68)[错误]:   TiHTTPClient:at   ti.modules.titanium.network.TiHTTPClient.getResponseXML(TiHTTPClient.java:562)   [错误]:TiHTTPClient:at   ti.modules.titanium.network.HTTPClientProxy.getResponseXML(HTTPClientProxy.java:129)   [错误]:TiHTTPClient:at   org.appcelerator.kroll.runtime.v8.V8Object.nativeCallProperty(母语   方法)[错误]:TiHTTPClient:at   org.appcelerator.kroll.runtime.v8.V8Object.callProperty(V8Object.java:73)   [错误]:TiHTTPClient:at   org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1155)   [错误]:TiHTTPClient:at   android.os.Handler.dispatchMessage(Handler.java:95)[错误]:   TiHTTPClient:在android.os.Looper.loop(Looper.java:137)[错误]:   TiHTTPClient:at   org.appcelerator.kroll.KrollRuntime $ KrollRuntimeThread.run(KrollRuntime.java:118)   [WARN]:TiBlob :( KrollRuntimeThread)[24,13680] getFile not not   支持非文件blob类型。 [警告]:TiBlob:   (KrollRuntimeThread)[8,13688]不支持getNativePath   非文件blob类型。 [INFO]:
  {"代码":0,"来源":{" responseText":"数组\ n(\ n [uploadToken] =>嗨!   我是一个代币!\ n [myNickname] => raholl \ n [nativePath] =>   文件:///storage/emulated/0/Pictures/app-name/tia-217296905.jpg \ n)的\ n""位置":" HTTP:// ** ****** / API / push_photo.php""状态":200,"结构域":空," readyState的":4,& #34; tlsVersion":0," connectionType":" POST"" validatesSecureCertificate":假,"状态文本":&# 34; OK""用户名":空,"密码":空," allResponseHeaders":"空:HTTP / 1.1   200   OK \ nConnection:保持活动\ nContent-长度:166 \ nContent类型:text / HTML \ nDate:周三,   2016年5月18日02:10:12 GMT \ nKeep-Alive:超时= 5,   最大= 100 \ n服务器:阿帕奇/ 2.2.22   (Debian的)\ nVary:接受编码\ NX-Android的接收-毫秒时间:1463537845271 \ NX-Android的发送-毫秒时间:1463537844807 \ NX供电-通过:PHP / 5.5.33-1〜dotdeb + 7.1 \ n&# 34;," responseXML的":空," responseData" {"文件":空,"的nativePath":空,"高度":0,"长度" 166"宽度":0," mime类型":" text / html的",& #34; apiName":" Ti.Blob""文本":"阵列\ N(\ n   [uploadToken] =>您好!我是一个代币!\ n [myNickname] => raholl \ n
  [nativePath] =>   文件:///storage/emulated/0/Pictures/app-name/tia-217296905.jpg \ n)的\ n""类型":2" bubbleParent" :真}" autoRedirect":真," apiName":" Ti.Network.HTTPClient"" autoEncodeUrl":真,&# 34;连接":假," bubbleParent":真," _events" {" disposehandle":{}}}"成功&# 34;:真}   [INFO]:警告:( KrollRuntimeThread)[8,13696]完成

这是什么行"解析XML时出错[错误]"来自(哪里?怎么解决?

一切看起来都很好,但错误看起来很严重......

任何想法都会受到赞赏。

1 个答案:

答案 0 :(得分:0)

LOL是

console.log(e);

中的

xhr.onload = function(e){
 divider("ONLOAD DONE");
 //console.log(JSON.stringify(e));
 //console.log(e);
 alert("done");
};

如果没有console.log,则不会出现任何错误,一切正常。可能 e 为空或无效的记录对象...