hi there!
I have some audio files in FLAC format and for the sake of maintaining the audio quality I want to use FLAC audio formats the problem is unity 2020 has a support for FLAC file now but when i try to download the files using UnityWebRequestMultimedia.GetAudioClip(urlToDonwload, AudioType.OGGVORBIS);
it give an error about FMOD file not supported. I tried the other formats but the audio quality gets compromised with those. so does some one know a way around this problem!?
also the AudioType doesnt have an option for FLAC format when downloading audio clip from a url.
HELP!
↧
How to use Unity Web request Multimedia to download FLAC audio File and convert it to audio clip?
↧
UnityWebRequest cannot receive data in some urls response
Hey guys.
I have some problems with UnityWebRequest.
I have several URLs to communicating with my server.
Some URLs working fine expectly and other few URLs not working expectly.
It's a weird thing that there is no error in any unity and my server. My server request with status 200 normally, but Unity client cannot receive any data from the server.
So I had testing my server on POSTMAN, Restlet Client, Curl, and even testing Axios on javascript. and it's working perfectly.
I don't know why UnityWebRequest cannot receive any data in some URLs responses.
My unity client version is 2019.2.12f1 and I tried 2019.3.0.f1 but it's not working too.
Thanks for reading my problem and please give me some advice about solving this problem.
↧
↧
Getting cast error from UnityWebRequest for an image
I am trying to load an image from a URL http://openweathermap.org/img/wn/{code}@2x.png. But I get cast error on loading
IEnumerator GetWeatherImage(string imageCode)
{
Debug.Log($"Code received {imageCode}");
UnityWebRequest www = UnityWebRequest.Get($"openweathermap.org/img/wn/{imageCode}@2x.png");
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
Texture weatherTexture = DownloadHandlerTexture.GetContent(www); // cast error
}
}
I tried pasting the URL in my browser and it works fine
Also followed the docs
↧
Issues with UnityWebRequest GET on Android
Hi everyone and thanks for your help!
I am trying to ask my web application if a user is ok to connect or not and I am currently struggling with webrequest on android.
First I worked with HttpWebRequest and it looks like this does not work on Android (code below) :
private bool TryConnect(string email, string password) {
var cert = new ForceAcceptAll();
string siteAddress = webSiteAddress + $"/Account/LoginSmartphone?email={email}&password={password}";
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(siteAddress );
webRequest.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
webRequest.Method = "GET";
using (HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse()) {
var html = new StreamReader(response.GetResponseStream()).ReadToEnd();
bool.TryParse(html, out bool connectionOk);
return connectionOk;
}
}
It worked perfectly on computer but I had no response on Android. So after searching on Google I found this solution instead :
IEnumerator GetRequest(string uri) {
using (UnityWebRequest webRequest = UnityWebRequest.Get(uri)) {
Debug.Log("Before send request");
//webRequest.certificateHandler = new ForceAcceptAll();
// Request and wait for the desired page.
yield return webRequest.SendWebRequest();
Debug.Log("Send request done");
switch (webRequest.result) {
case UnityWebRequest.Result.ConnectionError:
case UnityWebRequest.Result.DataProcessingError:
case UnityWebRequest.Result.ProtocolError:
//Error in login
Debug.LogError("Error: " + webRequest.error);
ConnectionError();
break;
case UnityWebRequest.Result.Success:
Debug.Log("Received: " + webRequest.downloadHandler.text);
if (ConnectionResponse(webRequest.downloadHandler.text)) {
ConnectionOk();
} else {
ConnectionError();
}
break;
}
}
}
On computer it works perfectly but when running on Android Emulator I have a timeout everytime. I hit the Debug.Log("Before send") but never the Debug.Log("Send Request done").
Does anyone know why is that and how to manage it properly?
Thanks and have a nice day!
↧
UnityWebRequest connects to the server in Editor but not in Android
Hello. I am with this problem that I can not find a solution to. Using **UnityWebRequest PATCH** (Unity 2017.4.31f1) to communicate with the server, if I test from the **Unity Editor** it **works fine**. But if I create an **built android** it doesn't work anymore and I get a **403 error**.
"403 forbidden X-CSRF token request header is missing"
(As a clarification, mention that this same error appears in Postman if I forget to delete the cookie that postman generates automatically and adds by default to the connection with the server. If I delete the cookie the error does not appear).
From what I understand, the submission made by UnityWebRequest from the Editor is different from the one made in the android version.
I have installed Unity 2020.3.2f1 but with this version it no longer works from the Editor either.
How can I verify what the UnityWebRequest is sending, and how can I correct this?
The code is this:
UnityWebRequest request = new UnityWebRequest (url, "PATCH");
byte[] bodyRaw = Encoding.UTF8.GetBytes (payload);
request.uploadHandler = (UploadHandler)new UploadHandlerRaw (bodyRaw);
request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer ();
request.SetRequestHeader ("Accept", "application/vnd.api+json");
request.SetRequestHeader ("Content-Type", "application/vnd.api+json");
request.SetRequestHeader ("Authorization", token);
yield return request.SendWebRequest();
string jsonString = request.downloadHandler.text;
if (request.isNetworkError || request.isHttpError) {
print ("ERROR: " + jsonString);
} else {
print ("OK: + jsonString);
}
Reading about similar errors, I have tried changing the values in "chunkedTransfer" and "useHttpContinue" but whitout results
Thank you very much for the help you can give me. I have finished the app and because of this error I cannot publish it.
↧
↧
Does UnityWebRequest.Abort also dispose the request?
When using [Abort][1] right before [Dispose][2] I receive a > System.ArgumentNullException : Value cannot be null. > Parameter name: _unity_self
public void Cancel()
{
_canceled = true;
if (_request != null)
{
_request.Abort();
_request.Dispose();
}
}
Is the disposal of the request included in the abortion?
[1]: https://docs.unity3d.com/2020.3/Documentation/ScriptReference/Networking.UnityWebRequest.Abort.html
[2]: https://docs.unity3d.com/2020.3/Documentation/ScriptReference/Networking.UnityWebRequest.Dispose.html
↧
how to get a text file/ video from azure blob storage to unity3d game Object (TextMP)
Hello everyone, I am making a Project which I want to load different Text file and a Video from Azure Blob Storage to unity. Actually I am a beginner and have no Idea how to Start. I wish I could find a help here.
So I made a Text Mesh Pro object, where I want to load my text,, I saw in unity Documentation Unity Web Request Get a script but I didn't understand well how should I use it or if it can help me..
I hope i can get an answer from You. Thank you
↧
Get Data from cloud to unity3d using unity web request
Hello, I have a video which I upload it on azure cloud and I want to load it in unity on 3d object. the point that if I want to change the video so I don't need to enter on unity and change it , I want to change it from the server. I hope I explained well my problem. I just don't know how to start with that. I hope really that someone can help me and Thank you
↧
Get data from Server
Hello everyone , I want to get different texts from server to Unity Text Mesh Pro component and the script works well and I can get for example 1 Text but I didn't know how to manage the script for different texts. this is the script.
public class GetMethod : MonoBehaviour
{
public TextMeshProUGUI getText;
public TextMeshProUGUI getText1;
string getURL = "https://myserver/text.txt";
string getURL2 = "https://myserver/text1.txt";
public string GetURL2 { get => getURL2; set => getURL2 = value; }
public void GetText()
{
StartCoroutine(GetTheText());
}
IEnumerator GetTheText()
{
string URL = getURL;
UnityWebRequest www = UnityWebRequest.Get(URL);
yield return www.SendWebRequest();
getText.text = www.downloadHandler.text;
string URL = getURL2;
UnityWebRequest www = UnityWebRequest.Get(URL);
yield return www.SendWebRequest();
getText1.text = www.downloadHandler.text;
}
so it looks like that but I know for getURL2 does not work so anyone can help me please ,,how to call other texts
↧
↧
why Video from a server doesn't appear in unity only voice ?
In my Project I want to load a video from azure server through a JSON file . to get the video is good it works but it doesn't show the video you can only hear the voice. I get many errors too as you see in my project :
![alt text][1]
[1]: /storage/temp/180995-videoprob.jpg
Does anyone know this Problem ? hope someone can help me
↧
How can I fill a list with images from an external source?
I have made a JSON file which contains items. Each item also has an image. The JSON file contains image URL's to images online. I want to use these images in my game. Ive made an item class which looks like this:
public class Items
{
public string Name;
public string Type;
public string ImgPath;
public Sprite Image;
}
The JSON file fills the first 3 strings. The Image attribute should be filled using the URL.
I have found solutions to get images from URL using UnityWebRequest. This results in a single image being retrieved, but I cant seem to figure out how to fill my list with images in order to display them in my game.
Ive been stuck on this for a while now, any help will be appreciated.
This is my WebRequests class:
public static class WebRequests
{
private class WebRequestsMonobehaviour : MonoBehaviour { }
private static WebRequestsMonobehaviour webRequestsMonobehaviour;
private static void Init() {
if (webRequestsMonobehaviour == null) {
GameObject gameObject = new GameObject("WebRequests");
webRequestsMonobehaviour = gameObject.AddComponent();
}
}
public static void GetImage(string url, Action onError, Action onSuccess)
{
Init();
webRequestsMonobehaviour.StartCoroutine(DownloadImage(url, onError, onSuccess));
}
static IEnumerator DownloadImage(string url, Action onError, Action onSuccess)
{
using (UnityWebRequest unityWebRequest = UnityWebRequestTexture.GetTexture(url))
{
yield return unityWebRequest.SendWebRequest();
if (unityWebRequest.isNetworkError || unityWebRequest.isHttpError)
{
onError(unityWebRequest.error);
}
else
{
onSuccess(((DownloadHandlerTexture)unityWebRequest.downloadHandler).texture);
}
}
}
}
And this is how I'm able to retrieve 1 image:
WebRequests.GetImage(url,
(string error) =>
{
Debug.Log("Error: " + error);
},
(Texture2D texture) =>
{
Debug.Log("Succes");
Sprite sprite = Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100.0f);
transform.GetChild(0).GetComponent().sprite = sprite;
});
↧
UnirtyWebRequest.Post sending empty uploadHanlder.data
Hi, A have a problem with unityWebRequest.Post, in the capture it says "Put" but I changed to test a solution in other foums but is not working, The problem is that the data is no being populated
The json file prints fine but the uploadHandle.data is not, in the second error in the console you can see is the same as before the HTTP/1.1 500 Internal Server Error.
I have tried WWWForm, the same HTTP 500 error.
The backend developer says with Postman is correct, and I have checked the json names and order.
Some links to solutions that not work for me :C
https://stackoverflow.com/questions/51526506/sending-unity-web-request-post-returning-empty-from-webhost
https://stackoverflow.com/questions/60862424/how-to-post-my-data-using-unitywebrequest-post-api-call
https://forum.unity.com/threads/unitywebrequest-post-returning-empty-string.632299/
![alt text][2]
![alt text][1]
I appreciate any help
[1]: /storage/temp/181577-webrequestproblemdebug.png
[2]: /storage/temp/181576-webrequestproblem.png
↧
Try catch alternative for HTTP request
Hello,
When connecting to a REST api, randomly and in some android devices I get errors when doing a POST. The errors are allways Curl error.... and they usually appear when the users are connected to free wifis and probably with wifis with extra security.
The issue is that when the error appear, the coroutine crashes, and fails, It doesnt return a http or network error and I am being unable to control the crashes because I cant use try catch with a return statement inside.
using (var request = new UnityWebRequest(string.Concat(server, url, applications, id, refreshToken), "POST"))
{
byte[] bodyRaw = Encoding.UTF8.GetBytes(form);
request.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
request.SetRequestHeader("Content-Type", "application/json");
request.SetRequestHeader("Authorization", "Bearer " + loginInfo.data.access_token);
yield return request.SendWebRequest();
↧
↧
Send WebRequest with Dto/object in body
How do I send dto's (or any serializable class) to/from the server? The server doesn't use strings but uses dto's instead. I tried an upload handler and various tutorials and manuals but none work for objects, they all only work for strings?
The server is this:
[HttpPost]
public async Task Login([FromHeader] string ip, UserCredentialsMinimalDto? userCredentials)
{
..
}
Unity code:
private IEnumerator SendTokenRequest(string uri)
{
using (UnityWebRequest webRequest = UnityWebRequest.Post(uri, "POST"))
{
webRequest.SetRequestHeader("content-Type", "application/json");
webRequest.SetRequestHeader("Accept", "application/json");
webRequest.SetRequestHeader("ip", "localhost"); // TODO: For testing.
byte[] bytesToSend = new System.Text.UTF8Encoding().GetBytes(JsonUtility.ToJson(new UserCredentialsMinimalDto("a", "1")));
webRequest.uploadHandler = (UploadHandler) new UploadHandlerRaw(bytesToSend);
yield return webRequest.SendWebRequest();
string[] pages = uri.Split('/');
int page = pages.Length - 1;
switch (webRequest.result)
{
case UnityWebRequest.Result.ConnectionError:
case UnityWebRequest.Result.DataProcessingError:
UnityEngine.Debug.LogError(pages[page] + ": Error: " + webRequest.error);
break;
case UnityWebRequest.Result.ProtocolError:
UnityEngine.Debug.LogError(pages[page] + ": HTTP Error: " + webRequest.error);
break;
case UnityWebRequest.Result.Success:
UnityEngine.Debug.Log(pages[page] + ":\nReceived: " + webRequest.downloadHandler.text);
break;
}
}
↧
I have some deprecated errors with WWW someone knows how to convert this lines and use UnityWebRequest instead of WWW
/*this is obsolete use UnityWebRequest*/
WWW www = new WWW("http://localhost:8888/action_login.php", form);
yield return www;
if (string.IsNullOrEmpty(www.error))
{
/*this is obsolete use UnityWebRequest*/
if (www.text.Contains("invalid email or password"))
{
infoText.text = "Invalid email or password";
}
else
{
infoText.text = "Loggin Sucessful...";
}
}
else
{
infoText.text = "Error Ocurred...";
}
↧
UnityWebRequest old header info
Hi
I am working on a project where I need to check the date of a file on a server and download the file if the file on the hdd is older that the one the server.
I can get the 'last-modified' information, but this has not always the correct time especially just after I replaced the file on the server. Most of the time I get the value from the old file.
I work in unity 2020.3.13f1 and use the following code to debug the header info, but every time I run this code I get the same results
especially stange that the 'date' value is also the same every time.
request = new UnityWebRequest(url);
//request.useHttpContinue = false;
//request = UnityWebRequest.Head(url);
yield return request.SendWebRequest();
Debug.Log("last-modified: " + request.GetResponseHeader("last-modified"));
foreach (KeyValuePair item in request.GetResponseHeaders())
{
if (item.Key == "date")
{
Debug.Log("Date: " + item.Value);
}
if (item.Key == "last-modified")
{
ConvertToDateTime(item.Value);
Debug.Log("Date Time File: " + File.GetLastWriteTime(downloadFilePath));
}
}
public static void ConvertToDateTime(string inputDate)
{
Debug.Log("inputDate: " + inputDate);
DateTime time = DateTime.Parse(inputDate);
_serverFileDateTime = time;
Debug.Log("Date Time Server: " + _serverFileDateTime);
}
After this I just check the dates against each other to check if the file needs to be downloaded or not.
Code run at : Thu, 29 Jul 2021 12:17:44 GMT
Output log:
last-modified: Thu, 29 Jul 2021 08:26:24 GMT
Date: Thu, 29 Jul 2021 09:29:35 GMT
inputDate: Thu, 29 Jul 2021 08:26:24 GMT
Date Time Server: 29-7-2021 10:26:24
Date Time File: 29-7-2021 11:41:32
If I wait a while I do get the correct 'last-modified' date/time, but I don't know how long this takes. Besides that I want to be able to check for updates manually.
It looks like unity caches the request or the header values, although I found some forum posts that this is not possible.
I contacted the webhosting supplier and they told me the server does not cache. So when I upload a file the 'last-modified' should be correct right away. I can confirm this when I check the header in google chrome. Here the time I get is 2 hours earlier, but this has to do with GMT -> UTC+2 I think.
Hopefully someone has an idea of what I am doing wrong, or something I can do to get the correct header data every request.
Tnx!
Rutger
↧
UnityWebRequest is dragging everthing down!
Recently, We built a new version of our project with Unity 2020.3.13f1, but we found that the response speed of UnityWebRequest was unprecedentedly slow!
API response speed in Unity 2020.3.13f1 is 0.80 seconds, but in Unity 2020.3.13f1 is 0.21 seconds!
Then we built it with 2020.3.15f2, but it’s the same.
If Unity adjusted or updated something about this between Unity 2020.3.7f1 and Unity 2020.3.13f1 or not?
And if any advice to fix this problem can be provided?
↧
↧
data property of DownloadHandlerAudioClip always returns null
I used DownloadHandlerAudioClip and UnityWebRequest classes in order to get an audio from a url. audio gets downloaded properly and I can play it using audio source but I can't access raw downloaded bytes. data property returns null and nativeData is empty (its length is 0). even the get method of audio clip doesn't work as expected and the array I get from it is the same array I give to it without any change (all array members remain 0). why this is happening?
↧
Save Remote Addressable Sprites
I can able to setup Remote Addressable sprites within my project. Total 445 high-resolution sprites I was downloading, loading, and unloading within my game but on each new run of the game, it, again and again, downloading sprites from the webserver.
For 445 high-resolution images, this is not a proper way to deal so I want to just download it one time from the webserver and then I want to save those within the local device so as per my game requirements, I can load and unload them using local Addressable system.
And the most important point, users don't require to consume their internet to download the same content multiple times.
What is the way to achieve this? Please guide me into this.
For 445 high-resolution images, this is not a proper way to deal so I want to just download it one time from the webserver and then I want to save those within the local device so as per my game requirements, I can load and unload them using local Addressable system.
And the most important point, users don't require to consume their internet to download the same content multiple times.
What is the way to achieve this? Please guide me into this.
↧
Can you post a json string as a body in Unity?
I'm trying to post a json string as the body of a UnityWebRequest but it just fails throws protocolerror and doesnt work.
I can post using postman.
I can get data using pretty much the exact same function except for a few changes.
Post just isnt working for me.
public static async Task PostData(string url, string data)
{
using(UnityWebRequest request = UnityWebRequest.Post(url, data))
{
request.SetRequestHeader("Content-Type", "application/json");
request.SetRequestHeader("Accept", "application/json");
var operation = request.SendWebRequest();
while(!operation.isDone)
{
await Task.Yield();
Debug.Log($"({request.downloadProgress}%)");
}
if(request.isHttpError || request.isNetworkError)
{
Debug.Log("Request failed...");
return null;
}
if(request.result == UnityWebRequest.Result.Success)
return request.downloadHandler.text;
return null;
}
}
↧