使用UnityWebRequest加载cdn资源数据,代码如下
UnityWebRequest request = UnityWebRequest.Get(url);
request.SendWebRequest();
while (!request.isDone) {
}
if (request.result != UnityWebRequest.Result.Success) {
return string.Empty;
} else {
return request.downloadHandler.text;
}
调用后报错,如下:
exception thrown: TypeError: Cannot set property '1' of undefined,TypeError: Cannot set property '1' of undefined
at _JS_WebRequest_Create (http://127.0.0.1:42514/game/webgl.wasm.framework.unityweb.js:3774:40)
at TransportJavaScript::DoRequest(TransportDoRequestArgsProto<HeaderHelper, DownloadHandler, UploadHandler, CertificateHandler, ResponseHelper> const&) (<anonymous>:wasm-function[11599]:0x561477)
at UnityWebRequestProto<UnityWebRequestTransport, AtomicRefCounter, RedirectHelper, ResponseHelper, DownloadHandler, UploadHandler, CertificateHandler, HeaderHelper, AsyncOperation>::Task_DoRequest(void*) (<anonymous>:wasm-function[11635]:0x562e12)
at UnityWebRequestProto<UnityWebRequestTransport, AtomicRefCounter, RedirectHelper, ResponseHelper, DownloadHandler, UploadHandler, CertificateHandler, HeaderHelper, AsyncOperation>::Job_ExecuteUnityWebRequest(UnityWebRequestProto<UnityWebRequestTransport, AtomicRefCounter, RedirectHelper, ResponseHelper, DownloadHandler, UploadHandler, CertificateHandler, HeaderHelper, AsyncOperation>*) (<anonymous>:wasm-function[11637]:0x5633d3)
at UnityWebRequestProto<UnityWebRequestTransport, AtomicRefCounter, RedirectHelper, ResponseHelper, DownloadHandler, UploadHandler, CertificateHandler, HeaderHelper, AsyncOperation>::Begin() (<anonymous>:wasm-function[11633]:0x562934)
at UnityWebRequest::Begin() (<anonymous>:wasm-function[11632]:0x562784)
at UnityWebRequest_CUSTOM_BeginWebRequest(Il2CppObject*) (<anonymous>:wasm-function[26596]:0xe1237b)
at UnityWebRequest_BeginWebRequest_m5850801A007A95F35CCBAA5E947FF385DB50AE0D (<anonymous>:wasm-function[57904]:0x15a6a98)
at UnityWebRequest_SendWebRequest_mA3CD13983BAA5074A0640EDD661B1E46E6DB6C13 (<anonymous>:wasm-function[57905]:0x15a6aa2)
at UnityWebRequestMgr_GetText_mF62BC785F1CC32341A3ACA9693DBB4DC913657F1 (<anonymous>:wasm-function[59124]:0x15de101)
at AssetRecordMgr_LoadAssetRecord_mA389E650AFC0DF3EEE18AE80C45917E6787901D0 (<anonymous>:wasm-function[59121]:0x15ddf69)
at AssetBundleManager_StartUp_mB484D1192B30F6B60D2C4E726F2A07E6ACFE9826 (<anonymous>:wasm-function[59119]:0x15dddae)
at GameRoot_Start_mEAE6F347030F5DFB2A66FF13C280A2A0EF300F94 (<anonymous>:wasm-function[59489]:0x15f0dd5)
at RuntimeInvoker_TrueVoid_t4861ACF8F4594C3437BB48B6E56783494B843915(void (*)(), MethodInfo const*, void*, void**, void*) (<anonymous>:wasm-function[112210]:0x221abe1)
at il2cpp::vm::Runtime::InvokeWithThrow(MethodInfo const*, void*, void**) (<anonymous>:wasm-function[114391]:0x22445dc)
at dynCall_iiii (<anonymous>:wasm-function[114766]:0x2258462)
at http://127.0.0.1:42514/game/webgl.wasm.framework.unityweb.js:1525:20
at invoke_iiii (http://127.0.0.1:42514/game/webgl.wasm.framework.unityweb.js:19545:10)
at il2cpp::vm::Runtime::Invoke(MethodInfo const*, void*, void**, Il2CppException**) (<anonymous>:wasm-function[114370]:0x2243b2e)
at il2cpp_runtime_invoke (<anonymous>:wasm-function[2409]:0x10c4c0)
at scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr*, bool) (<anonymous>:wasm-function[26975]:0xe390e5)
at ScriptingInvocation::Invoke(ScriptingExceptionPtr*, bool) (<anonymous>:wasm-function[24723]:0xda2669)
at MonoBehaviour::InvokeMethodOrCoroutineChecked(ScriptingMethodPtr, ScriptingObjectPtr) (<anonymous>:wasm-function[24658]:0xd9d3ed)
at MonoBehaviour::DelayedStartCall(Object*, void*) (<anonymous>:wasm-function[24672]:0xd9eae2)
at DelayedCallManager::Update(int) (<anonymous>:wasm-function[5225]:0x1a7e37)
at InitPlayerLoopCallbacks()::EarlyUpdateScriptRunDelayedStartupFrameRegistrator::Forward() (<anonymous>:wasm-function[24404]:0xd77081)
at ExecutePlayerLoop(NativePlayerLoopSystem*) (<anonymous>:wasm-function[5045]:0x1966d6)
at ExecutePlayerLoop(NativePlayerLoopSystem*) (<anonymous>:wasm-function[5045]:0x196771)
at MainLoop() (<anonymous>:wasm-function[22235]:0xc2ee57)
at dynCall_v (<anonymous>:wasm-function[114769]:0x2258482)
at http://127.0.0.1:42514/game/webgl.wasm.framework.unityweb.js:1525:20
at browserIterationFunc (http://127.0.0.1:42514/game/webgl.wasm.framework.unityweb.js:13183:13)
at callUserCallback (http://127.0.0.1:42514/game/webgl.wasm.framework.unityweb.js:11366:3)
at Object.runIter (http://127.0.0.1:42514/game/webgl.wasm.framework.unityweb.js:11427:4)
at Browser_mainLoop_runner (http://127.0.0.1:42514/game/webgl.wasm.framework.unityweb.js:11341:53)
at Function.<anonymous> (http://127.0.0.1:42514/game/unity-sdk/fix.js:34:19)
at f (http://127.0.0.1:42514/game/__dev__/WAGameSubContext.js:2:108216)
at http://127.0.0.1:42514/game/__dev__/WAGameSubContext.js:2:108666
at r.<anonymous> (http://127.0.0.1:42514/game/__dev__/WAGameSubContext.js:2:96981)
at http://127.0.0.1:42514/game/__dev__/WAGameSubContext.js:2:143904(env: Windows,mg,1.06.2206090; lib: 2.24.6)
请问这个问题解决了吗,什么原因?
我也遇到这个问题了,请问你怎么解决的呀?