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

View Generated Source (After AJAX/JavaScript) in Unity

$
0
0
I am trying to download page source from a given site that heavily uses Ajax / Javascript to Generate the source. What I am trying to do is find a way to get the source downloaded after this occurs in Unity. I am familiar with doing so in a basic C# application using the web browser component or with HtmlAgility Pack LoadFromBrowser method. However, I have tried to add win forms into the application with no success as well as HtmlAgilityPack and neither of those work. When trying to add winforms to the application I get "Could not register the window class, windows error 0" error and a null reference exception. Same goes for HtmlAgilityPack as the LoadFromBrowser I believe uses the webbrowser component. Am I missing something with UnityWebRequest that could get the job done?

How to replace WWW() with UnityWebRequest

$
0
0
I'm a complete beginner in this area, may someone help me? I currently have: string s; ... StartCoroutine(OutputRoutine(new System.Uri(paths[0]).AbsoluteUri)); ... private IEnumerator OutputRoutine (string url){ var output = new WWW(url); yield return output; s = output.text; } But that gives me a warning: *warning CS0618: `UnityEngine.WWW' is obsolete: `Use UnityWebRequest, a fully featured replacement which is more efficient and has additional features'* How I can do what the warning says without changing the way it currently works? I don't want to change anything, just update the code to be more efficient and stop giving me warnings Additional context, if needed: this code is from an example from [SFB][1], which I'm using to save/load text files. [1]: https://github.com/gkngkc/UnityStandaloneFileBrowser

UnityWebRequest.Post Returning Empty String

$
0
0
I'm pining a Rasa server through Ngrok and postman is working fine.. it was working in few test, but then like 3rd time test.. the return text will be empty any possible reason? I'm using Unity 2018.0.3.f2 Windows 10 I'm building it for android and Ios (unity cloud build) here my code in posting IEnumerator PostRequest_(string url, string json) { Debug.Log(url); var uwr = new UnityWebRequest(url, "POST"); byte[] jsonToSend = new System.Text.UTF8Encoding().GetBytes(json); uwr.uploadHandler = (UploadHandler)new UploadHandlerRaw(jsonToSend); uwr.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer(); uwr.SetRequestHeader("Content-Type", "application/json"); uwr.SetRequestHeader("Cache-Control", "no-cache"); uwr.SetRequestHeader("Pragma", "no-cache"); uwr.SetRequestHeader("Accept", "*/*"); uwr.SetRequestHeader("Accept-Encoding", "gzip, deflate"); yield return uwr.SendWebRequest(); if (uwr.isNetworkError) { Debug.Log("Error While Sending: " + uwr.error); } else { Debug.Log("Received: " + uwr.downloadHandler.text); itemData = JsonMapper.ToObject(uwr.downloadHandler.text); bool hasElement = false; foreach (var element in itemData) { hasElement = true; break; } if (hasElement){ TTSObj.OnInputText(itemData [0]["text"].ToString()); }else { Debug.Log("Received: Empty"); } }

A method for streaming custom audio from the hard drive

$
0
0
With the deprecation of *WWW.GetAudioClip*, *UnityWebRequestMultimedia.GetAudioClip* seems to be the main way to download custom audio off the internet and play it at runtime. Which is great and all, but what about loading custom audio off the player's hard drive? Surely there must be some synchronous method for creating an AudioClip using a file off the hard disc; something that doesn't require messing around with web code and coroutines. Is there some way to--for instance--use *File.ReadAllBytes()* at runtime and pass the resulting byte array into an *AudioClip*? (I notice that *[AudioClip.SetData()][1]* expects to receive a float[], which is decidedly not a byte array, and that the *[AudioClip.LoadAudioData()][2]* method seems to...be useless?) Is *UnityWebRequestMultimedia.GetAudioClip()* really the only game in town? Or is there something a little less cumbersome available for loading custom audio off the hard drive? [1]: https://docs.unity3d.com/ScriptReference/AudioClip.SetData.html [2]: https://docs.unity3d.com/ScriptReference/AudioClip.LoadAudioData.html

How to post images to mysql using unity webrequest?

$
0
0
Hello i need your help, I am trying to post image data in form of Base64string to a php script. It is working on my localhost in right way.But when i am using same logics for my web server, It only works when i am posting the small size images but not working when i am posting large size images. And even if small images are posted my webrequest with async operation keeps on overlooping and never return isDone ==true. Here is my c# code public void upload() { Sprite sp = GetComponent().sprite; byte[] bytes = sp.texture.EncodeToPNG(); string imgstr = Convert.ToBase64String(bytes); WWWForm insertInfo = new WWWForm(); insertInfo.AddField("servername", dbcon.Server_name1); insertInfo.AddField("username", dbcon.Username1); insertInfo.AddField("password", dbcon.Password1); insertInfo.AddField("database_name", dbcon.Database_name1); insertInfo.AddField("data_value", "Anyone"); insertInfo.AddField("img_value", imgstr); insertInfo.AddField("data_column_name", "actual_data"); insertInfo.AddField("image_column_name", "data_img"); insertInfo.AddField("table_name", "sft_table"); tryagain: using (UnityWebRequest dataInserturl = UnityWebRequest.Post("https://myserver.com/myphpfolder/Insertinformation.php", insertInfo)) { UnityWebRequestAsyncOperation web_Async_Operation = dataInserturl.SendWebRequest(); if (dataInserturl.isNetworkError || dataInserturl.isHttpError) { Debug.LogError("Insert B Error-" + dataInserturl.error); yield return new WaitForEndOfFrame(); // goto tryagain; } while (!web_Async_Operation.isDone) { Debug.Log("Progress=" + web_Async_Operation.progress); yield return new WaitForFixedUpdate(); } rawtext0 = dataInserturl.downloadHandler.text.Trim(); Debug.LogError("Rawtext=" + rawtext0); } Here is my php Code Thank you people in advance, if you have any solution or a better idea to perform such operation than please post your solutions.

See Request of WWW or UnityWebRequest, 403 error only from android in a specific url (GET)

$
0
0
Hello, I have a code that downloads data from a url. I have a problem that one Url gives me error 403 (Forbidden) only from android. When i get the url from editor or Windows build, all works perfectly. So if i could see the Request that WWW or UnityWebRequest does from android and Windows i would be able to compare whats going wrong. I tested it with two codes ( WWW and UnityWebRequest) and both give the same result. i tested it with other urls that contains xml, and it works. Url: http://www.mambiente.madrid.es/opendata/horario.xml WWW IEnumerator DownloadXml(string url, DateTime data = new DateTime()) { WWW www = new WWW(url); yield return www; ParseXML text = new ParseXML(); string file = www.text; UnityWebRequest IEnumerator GetRequest(string url, DateTime data, bool actualPolution) { using (UnityWebRequest webRequest = UnityWebRequest.Get(url)) { // Request and wait for the desired page. yield return webRequest.SendWebRequest(); if (webRequest.isNetworkError) { Debug.Log(url + ": Error: " + webRequest.error); } else { ParseXML text = new ParseXML(); string file = webRequest.downloadHandler.text; Debug.Log(url + ":\nReceived: " + file);

Convert code from HttpWebRequest to UnityWebRequest (SetRequestHeader)

$
0
0
Hello, I have problems downloading a xml from a specific url. Then someone of this forum solved me the problem with HttpWebRequest. [Http solution][1] I need to convert it because i want to use coroutines and i cant do it with HttpRequest. I tried to convert the code, but when i do it, it keeps failing. Whats wrong with my code? HttpWebRequestCode string xml; CookieContainer cookies = new CookieContainer(); HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create("http://www.mambiente.madrid.es/opendata/horario.xml"); webRequest.UserAgent = @"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36"; webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"; webRequest.Method = "GET"; XmlDocument xmldoc = new XmlDocument(); using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse()) { using (StreamReader streamReader = new StreamReader(webResponse.GetResponseStream())) { xml = streamReader.ReadToEnd(); xmldoc.LoadXml(xml); } } My try to convert it using (UnityWebRequest webRequest = UnityWebRequest.Get(url)) { if (actualPolution) { webRequest.SetRequestHeader("User-Agent", @"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36"); webRequest.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"); } // Request and wait for the desired page. yield return webRequest.SendWebRequest(); if (webRequest.isNetworkError) { Debug.Log(url + ": Error: " + webRequest.error); } else { ParseXML text = new ParseXML(); string file = webRequest.downloadHandler.text; Debug.Log(url + ":\nReceived: " + file); [1]: http://answers.unity.com/answers/1612416/view.html

JSON WebRequest works in 2018.2, throws 403 error in 2018.3

$
0
0
Since **Unity2017.2** we've been using a custom build pipeline that can be triggered by sending a JSON webrequest to the pipeline's API (using editor coroutines). I had specifically implemented this request using the **UnityWebRequest** class due to WWW being deprecated in the future. The implementation of this webrequest has worked all the way up to **Unity2018.2.21f1** without issue (see code snippet below). However, for some reason the exact same implementation returns a **response code 403 (forbidden)** in **Unity 2018.3.4f1**. I've been looking through patch notes and documentation for web requests in 2018.3, but I can't seem to find any significant changes, other than the WWW class being deprecated. If there's anyone out there who can point me in the right direction, I'd be eternally grateful. public static UnityWebRequest CreatePostRequest(string url, string jsonBody, string username, string password) { var request = new UnityWebRequest(url, "POST"); request.method = "POST"; byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonBody); request.uploadHandler = new UploadHandlerRaw(bodyRaw); request.downloadHandler = new DownloadHandlerBuffer(); request.SetRequestHeader("Content-Type", "application/json"); request.SetRequestHeader("Accept", "application/json"); request.SetRequestHeader("Authorization", BasicAuthorizationHeader(username, password)); return request; } public static string BasicAuthorizationHeader(string username, string password) { string auth = username + ":" + password; string final = "Basic " + EncodeStringAsBase64(auth); return final; } public static string EncodeStringAsBase64(string input) { byte[] bytesToEncode = Encoding.UTF8.GetBytes(input); string encodedText = Convert.ToBase64String(bytesToEncode); return encodedText; }

UnityWebRequest.POST calls to an HTTPS url throws "Unknown error" on specific device

$
0
0
Hello, just upgraded our backend server to HTTPS from HTTP, I tested it in the Editor and 4 devices. All fine except one of the devices, which gave an "Unknown error" error (.error property of the "UnityWebRequest" class). I switched back to HTTP and the error is gone, so it's caused by the HTTPS. The device is a Huawei Nova 2 and has Android 7. I've already tryed the .chunkedTransfer = false, and it doesn't work. Any ideas?

GZIP compression in Unity

$
0
0
Hello! I'm using UnityWebRequest.Get to pull gzipped assets. Whether or not I add request.SetRequestHeader("Accept-Encoding", "gzip") to my request, I notice that I get accept-encoding gzip in the response headers. However, the download size is the uncompressed size. What's going on here? This link seems to say we shouldn't be setting accept-encoding headers? https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.SetRequestHeader.html - Jed

How to return value from UnityWebRequest?

$
0
0
I have a script that connects to the database and retrieve data. The GetData function is called by other script. is there a way that I can return the data back to the caller? public IEnumerator GetData(){ using (UnityWebRequest wwww = UnityWebRequest.Get("http://localhost/BMS/LoadGame.php")) { yield return wwww.SendWebRequest(); if (wwww.isNetworkError || wwww.isHttpError){ Debug.Log(wwww.error); } else { Debug.Log(wwww.downloadHandler.text); //How to return the result to the caller? } } } The method that I know is to call another function in other script to pass the data, but this is a lot more troublesome. Is there any direct way that I can return the data to the caller? Thanks!

WWW.UnEscapeURL and WWW.EscapeURL cannot swap back?

$
0
0
I using UnEscapeURL with encoding big5 is work, input "%BC%D6 " return "樂". But i want to EscapeURL with encoding big5 is not correct. input "樂" return "%e6%a8%82" Debug.Log(WWW.UnEscapeURL("%BC%D6", System.Text.Encoding.GetEncoding("big5"))); Debug.Log(WWW.EscapeURL("樂", System.Text.Encoding.GetEncoding("big5"))); Output: 樂 %e6%a8%82 It mean EscapeURL with encoding is not work?

Issue assigning JSON Data to Class Structure

$
0
0
Hello there! Here's a bit of background information: ---------- I'm making a GET request to retrieve JSON data, and I'm trying to store that data into a structure of classes. Printing the retrieved data to the console works, but assigning it to the classes does not (it remains empty in the inspector after the request.) ---------- I’ve split the code into two sections. 1. Makes the web request and attempts to store the data into a class structure. 2. The current class structure ---------- Here is a link to the [JSON Data][1] I’m using. ---------- public class WebRequestTest : MonoBehaviour { public string uri = "https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=5min&apikey=demo"; public RootObject rootObj; void Start() { StartCoroutine(GetRequest(uri)); } IEnumerator GetRequest(string uri) { UnityWebRequest req = UnityWebRequest.Get(uri); yield return req.SendWebRequest(); Debug.Log(req.downloadHandler.text); rootObj = JsonUtility.FromJson(req.downloadHandler.text); } } Below is the structure for my classes so far. I'm imagining that the issue might be with TimeSeries.dataPeriods. (TLDR: I wasn't sure whether to use an array, a list, or something else; but I settled on a list.) [Serializable] public class RootObject { public MetaData metaData; public TimeSeries timeSeries; } [Serializable] public class MetaData { public string Information; public string Symbol; public string LastRefreshed; public string OutputSize; public string TimeZone; } [Serializable] public class TimeSeries { public List dataPeriods; } [Serializable] public class DataPeriod { public Data data; } [Serializable] public class Data { public string Open; public string High; public string Low; public string Close; public string Volume; } You may have noticed in the Data class that I stored all the numeric data as strings. I thought I'd need to store them this way at first because they are coming from JSON and then convert them later when needed. (Perhaps there is a more elegant way to handle this?) ---------- Final questions: 1. Am I handling comma separated objects the right way by using a list or should I be doing something else? 2. Does anything stand out as to whats preventing the data from being assigned into the RootObject class? 3. If you have any insights about what would be a good way to handle converting the numbers to ints/floats when the class is created, I would love to hear it! Thank you so much for reading this! I'm going to keep working on this and will post an update when I can. [1]: https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=5min&apikey=demo

Call JS function from Unity Script,How to call a JS Function from a Unity Script?

$
0
0
Hi, i try to call JS functions from Unity Script. I've tried some solutions, but none of them worked. When I try the solution from the official documentation, it doesn't work. https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html The ultimate goal is to send/receive easily message from both JS and Unity. I need your help ! Thanks

UnityWebRequest error on WebGL

$
0
0
Hi! Im having a lot of problems with UnityWebRequest and WebGL. My code is this: static IEnumerator GetText(string web) { Debug.Log("Iniciando petición" + web); UnityWebRequest webRequest = UnityWebRequest.Get(web); using (webRequest) { yield return webRequest.SendWebRequest(); if (webRequest.isHttpError) { throw new Exception("Could not connect to backend: " + webRequest.responseCode); } // Player results ID Player.Id = webRequest.downloadHandler.text; Debug.Log("User added!"); In editor It works perfectly, but when we try it in WebGL browser lauch this error, when this line is executed: yield return webRequest.SendWebRequest(); 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") at jsStackTrace (Ches81 WebGL.wasm.framework.unityweb:2:15158) stackTrace (Ches81 WebGL.wasm.framework.unityweb:2:15329) onAbort@http://chess81.x10.bz/Build/UnityLoader.js:4:9322 abort (Ches81 WebGL.wasm.framework.unityweb:2:497045) _dlopen (Ches81 WebGL.wasm.framework.unityweb:2:222751) @blob:http://chess81.x10.bz/74023ca5-995f-4e9a-8ade-19570c9d9fd9 line 2 > WebAssembly.instantiate:wasm-function[46858]:0xdff4b1 (blob:http://chess81.x10.bz/74023ca5-995f-4e9a-8ade-19570c9d9fd9 line 2 > WebAssembly.instantiate:wasm-function[46429]:0xded5a3) ... Please Help!!!! PD. May be @jonas-echterhoff knows... XD

UnityWebRequest error on WebGL

$
0
0
Hi! Im having a lot of problems with UnityWebRequest and WebGL. My code is this: static IEnumerator GetText(string web) { Debug.Log("Iniciando petición" + web); UnityWebRequest webRequest = UnityWebRequest.Get(web); using (webRequest) { yield return webRequest.SendWebRequest(); if (webRequest.isHttpError) { throw new Exception("Could not connect to backend: " + webRequest.responseCode); } // Player results ID Player.Id = webRequest.downloadHandler.text; Debug.Log("User added!"); In editor It works perfectly, but when we try it in WebGL browser lauch this error, when this line is executed: yield return webRequest.SendWebRequest(); 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") at jsStackTrace (Ches81 WebGL.wasm.framework.unityweb:2:15158) stackTrace (Ches81 WebGL.wasm.framework.unityweb:2:15329) onAbort@http://chess81.x10.bz/Build/UnityLoader.js:4:9322 abort (Ches81 WebGL.wasm.framework.unityweb:2:497045) _dlopen (Ches81 WebGL.wasm.framework.unityweb:2:222751) @blob:http://chess81.x10.bz/74023ca5-995f-4e9a-8ade-19570c9d9fd9 line 2 > WebAssembly.instantiate:wasm-function[46858]:0xdff4b1 (blob:http://chess81.x10.bz/74023ca5-995f-4e9a-8ade-19570c9d9fd9 line 2 > WebAssembly.instantiate:wasm-function[46429]:0xded5a3) ... Please Help!!!!

Red 8x8 Question mark texture global replacement

$
0
0
Hello! There are numerous questions covering this, none with a great answer that I've seen. I'm building an app heavily reliant on live images from the web, and a caching plugin called unicache. We have had some corrupt files from the backend, and very rare errors with the caching plugin that result in an 8x8 texture being displayed which is a red question mark. Many of the community answers rely on fixing the underlying problem. We're at a place where that seems to have been solved, but is there a solid way to globally just replace that question mark texture with something more professional?

UnityWebRequestTexture Unable to Load From Directories Containing '#' or '+' Characters

$
0
0
I'm using UnityWebRequestTexture to load images from my file system into my game. Here is my code: private IEnumerator ImageLoadCoroutine(int i) { GameObject imgObj; Texture2D imageTex = null; //string activeDir = fileList[i]; //activeDir = activeDir.Replace("+", "+"); // Does not fix issue! //using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(activeDir)) using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(fileList[i])) { yield return uwr.SendWebRequest(); if (uwr.isNetworkError || uwr.isHttpError) { // "+" dirs have HttpError Debug.Log(uwr.error + "(" + uwr.isNetworkError + ", " + uwr.isHttpError + ")"); } else { // Get downloaded asset bundle imageTex = DownloadHandlerTexture.GetContent(uwr); } } imgObj = Instantiate(imagePrefab); imgObj.transform.SetParent(imageContainer.transform); imgObj.transform.localPosition = Vector3.zero; imgObj.transform.localRotation = Quaternion.identity; imgObj.transform.localScale = Vector3.one; imgObj.GetComponent().texture = imageTex; imgObj.GetComponent().enabled = false; imgObj.GetComponent().enabled = false; imagesLoaded++; imageList[i] = imgObj; } However, when I try to load images from directories containing the '+' or '#' characters (i.e. "C:\Users\MyUser\Documents\Unity Projects\The+++Folder"), I get the HttpError: "HTTP/1.1 404 Not Found" Directories containing other special characters like @, &, or = work fine. Using the Replace function to replace the characters with their character entity reference code (i.e., replacing all instances of "+" with "& plus ;") did not fix the problem. What is the source of this issue, and is there a way around it? I'd rather not be arbitrarily restricted in which valid folder names actually work with my program. Thanks!

FtpWebRequest and explicit ftp

$
0
0
Hello I access file on my ftp folder without problem since last week. Now I need to use explicit TLS security and nothing work well :( I try to use EnableSsl but it's don't work. Any idea ? FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://myurl.com/test.txt"); request.Method = WebRequestMethods.Ftp.DownloadFile; request.EnableSsl = true; request.Credentials = new NetworkCredential(ftpLogin, ftpPassword); FtpWebResponse response = (FtpWebResponse)request.GetResponse(); Stream responseStream = response.GetResponseStream(); StreamReader reader = new StreamReader(responseStream); Console.WriteLine(reader.ReadToEnd()); Console.WriteLine("Download Complete, status {0}", response.StatusDescription); reader.Close(); response.Close(); Error message : System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> Mono.Security.Interface.TlsException: Handshake failed - error code: UNITYTLS_INTERNAL_ERROR, verify result: UNITYTLS_X509VERIFY_NOT_DONE\r\n at Mono.Unity.Debug.CheckAndThrow (Mono.Unity.UnityTls+unitytls_errorstate errorState, Mono.Unity.UnityTls+unitytls_x509verify_result verifyResult, System.String context, Mono.Security.Interface.AlertDescription defaultAlert) ...

I get byte[] from unitywebrequest.get . now how can i change byte[] to another like mesh or assetbundle?

$
0
0
typeconversion is a real mess.it always giving me error that byte[] cannot be converted into assetbundle or other type.(there are few exceptions like texture as they have methods to convert from byte[] but real problem is when i dont have that facility).actually i wanted assetbundle.manifest file from server but due to unitywebrequest.get() request it got converted into byte[] now i cannot convert it back to assetbundle.manifest
Viewing all 387 articles
Browse latest View live


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