Quantcast
Channel: Questions in topic: "webrequest"
Viewing all 387 articles
Browse latest View live

Get Contents of Folder Using UnityWebRequest

$
0
0
I'm using UnityWebRequest to grab files from the StreamingAssets folder in Android. At the start of my game I want to copy all the files from StreamingAssets to persistentDataPath so I can use normal file operations. To do this, I'd need to iterate through all the files within a folder I have in StreamingAssets. How do I do this using UnityWebRequests? I don't believe any normal file operations work because of how Android packs all the files from StreamingAssets into the apk.

Finish UnityWebRequest before going further in Code

$
0
0
Hello people! The last few days i struggled with the following problem: my output should look like this -> First Log, Second Log some response data, Third log But in fact it always looks like this -> First Log, Third Log, Second Log some response data I have litteraly searched the whole internet but i didnt found a solution. Can anyone help me please? :) Best regards Alex using UnityEngine; using System.Collections; using UnityEngine.Experimental.Networking; using UnityEngine.Networking; public class Test : MonoBehaviour { void Start() { Debug.Log("First Log"); StartCoroutine(GetText()); Debug.Log("Third Log"); } IEnumerator GetText() { string url = "some url"; UnityWebRequest www = UnityWebRequest.Post(url,"some Data"); yield return www.SendWebRequest(); if (www.isError) { Debug.Log(www.error); } else { // Show results as text Debug.Log("Second Log: " + www.downloadHandler.text); // Or retrieve results as binary data //byte[] results = www.downloadHandler.data; // Debug.Log(results); } } }

Error in BUILD with UnityWebRequest but not in Editor

$
0
0
Hello i have the following code that's work perfectly in Editor but just crash in .exe buil and WebGL. In WebGL i have the followings errors. An error occurred running the Unity content on this page. See your browser JavaScript console for more info. The error was: uncaught exception: abort("To use dlopen, you need to use Emscripten's linking support, see https://github.com/kripken/emscripten/wiki/Linking") I searched informations about Emscripten and Linking but i don't understand how to use it and how to solve my problem with it. And i don't think it will solve the problem in the .ex because the error is different : ArgumentNullException : the value can not be null. Can someone hel me ?

Unknow error webRequest

$
0
0
I'm doing an apk which when I run it on my cell phone gives me the following error "Unknow error" but the strangest thing is that if it works normally when I run it from unity, I used the following code to show me what the error was when I executed it on my cell phone because unity works perfectly/Estoy haciendo una apk la cual cuando la ejecuto la en mi celular me da el siguiente error "Unknow error" pero lo mas extraño es que si funciona normal mente cuando la ejecuto desde unity, utilice el siguiente código para que me mostrara cual era el error cuando la ejecutaba en mi celular ya que en unity funciona perfectamente : if (webRequest.isNetworkError ) { advertencia.SetActive(true); advertencia.GetComponent().text=webRequest.error; } check if my apk was connected to the internet with the following code that shows a text and if it connects to the internet/revise si mi apk se conectaba a internet con el siguiente código que muestra un texto y si se conecta a internet : if (Application.internetReachability == NetworkReachability.NotReachable) { advertencia.SetActive(true); Debug.Log("Error. Check internet connection!"); } I do not know what happens : /, if someone can help me, I would appreciate it very much/no se que pasa : / , si alguien me puede ayudar se lo agradecería mucho PD: Sorry if this is a bit strange written in English sometimes google translates rare XD and then very rarely you see the questions are solved when asked in Spanish and it is also difficult to find information in this language : / @Guayavas

http url not work in webgl (unity2019.3).

$
0
0
**HTTP** URL not work in WebGL (unity2019.3). why **HTTP** URL respond unknown error. **HTTPS** URL working fine. when try to download data (ex: Texture) from **HTTP** URL using UnityWebRequest it show unknown error.. Thanks...

UnityWebRequest works fine until second start of unity

$
0
0
Hi Forum, I'm experiencing strange behaviour with a UnityWebRequest. When I start the game the first time after Unity launched, it returns the expected string, also when called several times - when it's still the first gamestart. When the game is stopped and restarted, the string is empty. What's wrong? Or is this a reproducable bug? (Version 2018.4.1f1) Any help appreciated, I attached the code: using UnityEngine; using UnityEngine.Networking; using System.Collections; public class GameServer : MonoBehaviour{ protected string url = "http://words.lkl/whatword-server/"; protected string noCacheUrl; protected WWWForm postData; protected string result = ""; protected ServerCallback callback; public WWWForm PostData { set { this.postData = value; } } public string Url { set { this.url = value; } } public string Result { get { return result; } } public ServerCallback Callback { set { callback = value; } } public void Start() { postData = new WWWForm(); } public void StartRequest(WWWForm newPostData = null, bool json = false) { noCacheUrl = url + "?t=" + GL.getUTCTime(); if (null != newPostData) PostData = newPostData; StartCoroutine("PostRequest"); } public IEnumerator PostRequest() { UnityWebRequest webRequest = UnityWebRequest.Post(noCacheUrl, this.postData); { // Request and wait for the desired page. yield return webRequest.SendWebRequest(); string[] pages = this.url.Split('/'); int page = pages.Length - 1; if (webRequest.isNetworkError) { Debug.Log(pages[page] + ": Error: " + webRequest.error); callback(""); } else { // receive Datastring this.result = webRequest.downloadHandler.text; // AT this point the string is empty in case of error, so no need to check in the callback callback(this.result); } } } public delegate void ServerCallback(string wwwResult); }

Unity MacOS notarization - libcurl.dylib: The binary uses an SDK older than the 10.9 SDK

$
0
0
Using Unity 2019.1.8f1 on MacOS 10.13.6 High Sierra

I've been trying to put our app through the MacOS notarization process, so that it doesn't trigger Gatekeeper alerts when downloaded & run on newer versions of MacOS ([https://developer.apple.com/documentation/security/notarizing_your_app_before_distribution/customizing_the_notarization_workflow][1])

---------- Unfortunately, libcurl.dylib gets included in the .app, and causes the notarization process to fail: "issues": [ { "severity": "error", "code": null, "path": "<>.app/Contents/MacOS/libcurl.dylib", "message": "The binary uses an SDK older than the 10.9 SDK.", "docUrl": null, "architecture": "x86_64" } ----------

I just don't know enough about how Unity decides to include libraries and where it gets them from. I'm wondering two main things:

**a)** what prompts Unity to include libcurl.dylib? i.e. is it only included due to old references to the WWW class? If I updated to only use UnityWebRequest would this issue be sidestepped?
**b)** where does this version of the libcurl.dylib file come from, and can I update it to use a newer build of this library somehow?

Any insights appreciated.

[1]: https://developer.apple.com/documentation/security/notarizing_your_app_before_distribution/customizing_the_notarization_workflow

UnityWebRequest POST Fail on Samsung Note8

$
0
0
i use UnityWebRequest post data,it's work good,but just on Samsung Note8, UnityWebRequest responseCode = 0, error ="Unknow Error" i already try set useHttpContinue = false, but it's no use, i try to GET google ,Samsung Note8 is work i try to GET Apple GetAppVersionAPI, Samsung Note8 is not work i try to POST Data to my company API, Samsung Note8 is not work i try to POST https://ptsv2.com/t/ckyhc-1562726337 ,Samsung Note8 is work any can help me?

How to send a UnityWebRequest.GET with a raw json body?

$
0
0
How can I send a UnityWebRequest.GET with a raw json body? There is no overloaded function of **UnityWebRequest.Get** that let me send a bodyData just like **UnityWebRequest.Post** or **UnityWebRequest.Put** ![alt text][1] [1]: /storage/temp/143152-test.jpg

Unity 2018 hits don't show in Google Analytics

$
0
0
Since moving to Unity 2017/2018 from Unity 5.6, suddenly analytic data to Google Analytics does not arrive anymore. The server says 200 (ok) and there are no errors whatsoever. If the same url is used in the browser, the hit shows as expected. When comparing the traffic between a working 5.6 version and a non-working 2018 version, there is almost no difference: GET https://www.google-analytics.com/collect?v=1&ul=en&sr=1>> blablathequery HTTP/1.1 Host: www.google-analytics.com Accept: */* Accept-Encoding: identity User-Agent: UnityPlayer/>> 5.6.6f2 (http://unity3d.com) X-Unity-Version: >> 5.6.6f2 vs GET https://www.google-analytics.com/collect?v=1&ul=en&sr=1>> blablatheexactsamequery HTTP/1.1 Host: www.google-analytics.com Accept: */* Accept-Encoding: identity User-Agent: UnityPlayer/>> 2018.2.19f1 (UnityWebRequest/1.0, libcurl/7.52.0-DEV) X-Unity-Version: >> 2018.2.19f1 Content-Type: application/x-www-form-urlencoded So what gives? Okay, I actually already know the answer, but I want to help people with the same issue (including future me). Here it comes:

Does AWS work with hololens for asset bundle downloading and general GET, PUT, POST requests ?

$
0
0
Hi, I am new to web services and I am going to start a hololens project where I have to download assetbundles hosted in cloud and preferably AWS. I also need basic web services like GET, PUT, POST. Before I start, **I wanted to know whether AWS supports hololens (UWP) ? If Yes, which SDK of AWS should I use ?**

Wait for page to load before getting HTML from website

$
0
0
I am using UnityWebRequest to get data from an api that I created. It uses javascript/jQuery to get data from a server and I used ajax to stop the page from loading before the api gets the data. I need to wait for the page to load before I get the HTML from the api. Please Help! Javascript/JQuery: var playlistName = document.location.href.split("#")[1] $.ajax({ url: "https://cors-anywhere.herokuapp.com/https://gaana.com/playlist/" + playlistName, success: function(html) { var htmlPrev = document.outerHTML; document.write(html) var elements = document.getElementsByClassName("draggable "); var data = {name: document.getElementsByClassName("_t1")[0].children[0].textContent, image: document.getElementsByClassName("_at_g1")[0].children[0].src, data: []} for (var element of elements) { var currentJSON = JSON.parse(element.getElementsByTagName("span")[0].textContent); var title = currentJSON.title; var img = currentJSON.atw; data.data.push({title, img}); } console.log(data) document.outerHTML = htmlPrev; document.body.textContent = JSON.stringify(data) }, async:false, cache:false }); Unity: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; using UnityEngine.SceneManagement; using TMPro; public class CallApi : MonoBehaviour { public TMP_InputField playlistId; public static string playlistData; public void CallPub() { StartCoroutine(Call()); } IEnumerator Call() { using (UnityWebRequest request = UnityWebRequest.Get("https://gaana-api--programmer101.repl.co/#" + playlistId.text)) { yield return request.SendWebRequest(); if (request.isNetworkError) { Debug.Log(request.error); } else { CallApi.playlistData = request.downloadHandler.text; SceneManager.LoadScene("LoadingScene"); } } } }

How do I have multiple UnityWebRequests in one coroutine?

$
0
0
I have a DLC scenario in my mobile app. It's one download button that will retrieve 2 asset bundles from HTTP links. I've set up an IEnumerator that goes through a UnityWebRequest, gets the asset bundle, stores it, and then disposes itself. The coroutine gets to line 77 where the second UWR should start, and I get this error message: ---------- "InvalidOperationException: Cannot get content from an unfinished UnityWebRequest object" ---------- So, what's going on here? I check to see if the UWR's Download Handler is finished and then dispose of both the handler and the UWR itself. So why am I getting an error message saying that there's an unfinished UWR object? I'm missing something here... Thanks for the help! Here's my code: ---------- #elif UNITY_IOS || Unity_Editor using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle(myaamiakiAssets)) { Debug.Log("Downloading audio assets."); yield return uwr.SendWebRequest(); if (uwr.isNetworkError || uwr.isHttpError) { Debug.Log(uwr.error); downloadButton.SetActive(true); downloadingIcon.SetActive(false); yield break; } else { // Get downloaded asset bundle AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(uwr); downloadingIcon.SetActive(true); downloadButton.SetActive(false); if (uwr.downloadHandler.isDone) { Debug.Log("Audio assets downloaded."); bundleStorage.myaamiakiAssets = bundle; uwr.downloadHandler.Dispose(); uwr.Dispose(); } } } using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle(myaamiakiScene)) { Debug.Log("Downloading scene asset."); if (uwr.isNetworkError || uwr.isHttpError) { Debug.Log(uwr.error); downloadButton.SetActive(true); downloadingIcon.SetActive(false); yield break; } else { // Get downloaded asset bundle AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(uwr); downloadingIcon.SetActive(true); downloadButton.SetActive(false); if (uwr.downloadHandler.isDone) { Debug.Log("Scene asset downloaded."); bundleStorage.myaamiakiScene = bundle; StartCoroutine(MyaamiakiLoadAndStore()); downloadingIcon.SetActive(false); startButton.SetActive(true); //save asset locations metaSaver.SaveGame(); yield break; } } } #endif

Weird problem with Async Task and UnityWebRequest

$
0
0
Hi everyone Currently, I am struggling with a weird problem. I am using UnityWebRequest to retrieve data from an API and I am using async Tasks to do this. This is a basic working task which awaits the SendWebRequest() method:

public static async Task Request(string url) { UnityWebRequest request = fetchPrep(url); // function which prepares request for API fetch await request.SendWebRequest(); if (request.isHttpError) { throw new System.Exception("HTTP ERROR " + request.error + url); } JsonSerializerSettings setting = jsonSerializerPrep(); string json = request.downloadHandler.text; Debug.Log(json); T fetch = JsonConvert.DeserializeObject(json); return fetch; } As I said this code works and there are no errors. Now I wanted to experiment with async tasks to improve this library: [glTFast][1]
But if I try to implement an async task with an await SendWebRequest() in the class [GltfAsset.cs][2] just like in my example, it doesn't work and says:
> Assets\GLTFast\GltfAsset.cs(31,13):> error CS1061:> 'UnityWebRequestAsyncOperation' does> not contain a definition for> 'GetAwaiter' and no accessible> extension method 'GetAwaiter'> accepting a first argument of type> 'UnityWebRequestAsyncOperation' could> be found (are you missing a using> directive or an assembly reference?)
Could you explain why it is working in my example? I am using the same "using's" and in my example an own class in my own namespace with no extensions..
Thanks in advance! [1]: https://github.com/atteneder/glTFast [2]: https://github.com/atteneder/glTFast/blob/master/Runtime/Scripts/GltfAsset.cs

Android can't download the audio

$
0
0
Hi all, I write the code ,that I want to use TTS ,and it's can work on PC not Android. Why it can't work on Android ? IEnumerator DownloadTheAudio() { string url = "https://translate.google.com/translate_tts?ie=UTF-8&total=1&idx=0&textlen=32&client=tw-ob&q=cat&tl=En-gb"; using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(url, AudioType.MPEG)) { yield return www.SendWebRequest(); if(www.isNetworkError || www.isHttpError) { Debug.Log(www.error); } else { AudioClip source = DownloadHandlerAudioClip.GetContent(www); _audio.clip = source; _audio.Play(); } }

Unity Web Request fails after exporting

$
0
0
Hey everyone, I'm using UnityWebRequest in order to make a request on my android app. This works perfectly on the editor and I get the correct response code in a blink of an eye. But after I export the app to Gradle, the web request fails. The cause of failure is "connection timeout". The weird thing is sometimes it works flawlessly after exporting, but most times it timeouts. I know that this is a network issue. But why is it working 100 percent of times in the editor, and it works like 5 percent of the time after exporting. I also have internet set to required in the player settings.

Android crashes while receiving multiple files from UnityWebRequest

$
0
0
Hi guys, i have a problem puzzling me for some days. Basically i have created a grid of sprites and i am downloading many pictures from the web. The problem is that my app crashes if i download many of them ( 150 or so). I am receining the picture using the UnityWebrequestTexture and then DownloadHandlerTexture. After that i apply it to the sprite and then i save it to the device storage using File.WriteAllbytes. I tried using delay ( IEnumerator for each request with a delay of 1 sec but even then it crashes. I saw somewhere that this is issue has to do with memory usage and i should use streams. Any ideas? thanks in advance

Image upload API works with postman but not working with Unity.

$
0
0
I'm using Unity 2018.3.14f1. I have created API for uploading image in php. Which is working well in the postman and not working in unity editor, All the time it gives me following log "HTTP/1.1 403 Forbidden". Here is my code: IEnumerator UploadImage() { yield return new WaitForEndOfFrame(); Texture2D screenImage = new Texture2D(Screen.width, Screen.height); screenImage.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); screenImage.Apply(); byte[] imageBytes = screenImage.EncodeToPNG(); WWWForm form = new WWWForm(); form.AddBinaryData("file", imageBytes, "screenShot.png", "image/png"); using (var w = UnityWebRequest.Post(screenShotURL, form)) { yield return w.SendWebRequest(); if (w.isNetworkError || w.isHttpError) { print(w.error); } else { print("Finished Uploading Screenshot"); } } } Here is php script : if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"] < 20000000000)) { if ($_FILES["file"]["error"] > 0) { //echo "Return Code: " . $_FILES["file"]["error"] . ""; } else { echo "Upload: " . $_FILES["file"]["name"] . ""; echo "Type: " . $_FILES["file"]["type"] . ""; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . ""; if (file_exists("Images/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "Images/" . $_FILES["file"]["name"]); echo "Stored in: " . "Images/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; }

How to send a report to server when the game is being closed?

$
0
0
I'm writing a plugin for Unity which needs to `yield return UnityWebRequest.SendWebRequest()` at some points in the game session. Ideally, I also need to send such request if the user closes the game (e.g. by closing the window from the operating system where the game runs). ---------- Actually, for my case, either `onDisable`, `onDestroy` or `onApplicationQuit` would do, however it seems that I can't start a coroutine there because at application termination all gameObjects are getting destroyed and there is simply not enough time to process the web request: not in one frame, not even in a few frames if there were any "grace period" at application closure. How do games solve such issues? ---------- A solution that comes to mind is to try to send data regularly. However, I'm already doing that. So, the problem is with that last request which doesn't get sent because the application is getting closed abruptly. ---------- Another solution I could think of is to store data which needs to be send (e.g. to PlayerPrefs or to some file) and *on the next app launch* check if there is any data pending to be sent. However, this won't always work for my case because: 1. The game may never be launched again. The user may just uninstall it. So, data will be lost 2. My server has a max allowed time after which the request will be rejected, so it has to be sent within the game session or shortly after, not 1 month after ---------- Yet another solution: download an executalbe file which would launch in the background, and if the game is closed then in onApplicationQuit use `System.Diagnostics.Process` to run that executable and do the request. However, this is bad in 2 respects: 1. Can't work cross-platform (would need separate executables for Windows, Mac, Linux and other platforms - ideally I want the plugin to run on every platform to which Unity can deploy 2. Each executable would need to handle the network logic in its own way - a work overhead compared to the simple, unified interface Unity offers.

Is the UnityWebRequest header of Android build of Unity2019 correct?

$
0
0
I noticed that after upgrading to Unity 2019.2.3, the UserAgent on Android builds is the same as on UnityEditor. Has the specification changed? ![left Unity2018.4 right Unity2019.2][1] The unity package of the project used for testing. You can test it by creating a new project in each Unity version and building Android. [unity package][2] [1]: /storage/temp/145751-ss.png [2]: /storage/temp/145746-heddertest.zip
Viewing all 387 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>