Quantcast
Channel: Questions in topic: "httpwebrequest"
Viewing all 190 articles
Browse latest View live

HTTPWebRequest.GetResponce for NTLM protocol not working on Android

$
0
0
I am trying to access data from IIS Server protected by NTLM protocol using HTTPWebRequest, which works fine on unity editor( windows ) but fails in Android Mobile App. I am getting 401 Unauthorized Access error, but works fine in editor and getting the expected response. Please help me, Please let me know, if there is any alternative through which i can access the server which is protected(NTLM protocol, I need to provide the authentication) Server shall be accessed successfully every time through browser, both in Desktop and in Mobiles.

Date request header is missing from http request(UnityWebrequest)

$
0
0
I am trying to send a GET request to an API that requires the Date request header. However UnityWebRequest does not send it automatically (I have checked with https://requestb.in/) and I cannot set it manually since "date" is one of the protected headers. I am able to communicate with the API successfully if I use the WWW class (which does allow me to set the "date" header manually) but am trying to do the same with the UnityWebRequest since WWW will be deprecated eventually. So, how can I make sure that the "date" request header is sent? Is there a solution or do I have to use an object from a different library such as .NET's HttpWebRequest? Thanks

HttpWebRequest timed out behind proxy

$
0
0
Hi, I try to access web services behind a proxy. Until now, I used unitywebrequest but I understood that proxy configuration wasn't handled by them. So I changed my code to use HttpWebRequest as it allows manual proxy configuration. I wrote a simple code to test this, but I'm still getting timeout. HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(ADMIN_URL); hwr.Method = "HEAD"; hwr.Timeout = 5000; WebProxy proxy = new WebProxy(PROXY_URL, true); proxy.Credentials = new NetworkCredential(myLogin, myPassword); hwr.Proxy = proxy; try { using (HttpWebResponse response = (HttpWebResponse)hwr.GetResponse()) { Debug.Log("response: " + response.StatusCode); } } catch (Exception e) { Debug.Log("Serveur not reachable: " + e.GetBaseException().Message); } If I remove the proxy configuration (and use a connexion without proxy) it works. If i use the same code in a wpf .NET application (with proxy), it works. I runned my tests through the Unity editor and with a pc standalone build. My Unity version is 5.4.1f1 If you have any hint that can helps me... thank you

Does overriding UnityWWWRequestDefaultProvider works for UnityWebRequest?

$
0
0
My project suffers from web cache problem in iOS client. We used UnityWebRequest with SetRequestHeader("Cache-Control", "max-age=0, no-cache, no-store"); SetRequestHeader("Pragma", "no-cache"); but it does not works well. I found that overriding iOS native function which used by unity : https://docs.unity3d.com/Manual/iosCustomWWWRequest.html but it says this sample works for WWW class (not UnityWebRequest class). I want to know that whether this sample works to UnityWebRequest too.

HttpWebRequest with Networkcredentials

$
0
0
Hi, I am trying to access a URL using (HttpWebRequest)WebRequest.Create(urlAddress). by giving authenticate using Network credentials. But in UNITY3D its giving the below error. WebException: The remote server returned an error: (401) Unauthorized. System.Net.HttpWebRequest.CheckFinalStatus (System.Net.WebAsyncResult result) System.Net.HttpWebRequest.SetResponseData (System.Net.WebConnectionData data) Thanks Bharath

How can I display text from a webrequest?

$
0
0
I am using a HTTP request to try and access a REST endpoint. I want to display the text I get in a canvas but I can't seem to get the output of the request to display in the Canvas. using UnityEngine.Networking; class Rest_test : MonoBehaviour { public TextMesh thistext; // Use this for initialization void Start () { StartCoroutine (GetText ()); } IEnumerator GetText() { UnityWebRequest www = UnityWebRequest.Get("http://jsonplaceholder.typicode.com/posts/1"); www.downloadHandler = new DownloadHandlerBuffer(); yield return www.Send(); if(www.isError) { Debug.Log(www.error); } else { // Show results as text Debug.Log(www.downloadHandler.text); // Or retrieve results as binary data //byte[] results = www.downloadHandler.data; } } void Update () { thistext.text = GetText (); } } I'm pretty new to C# and Unity so i may be missing something very basic. I get the following error when I add the script to my scene: Assets/Rest_test.cs(30,18): error CS0029: Cannot implicitly convert type `System.Collections.IEnumerator' to `string'

why does UnityWebRequest want Dispose() ?

$
0
0
The [Unity Docs][1] state:> Signals that this [UnityWebRequest] is no longer being used, and should clean up any resources it is using.>> You must call Dispose once you have finished using a [UnityWebRequest] object, regardless of whether the request succeeded or failed. Why doesn't UnityWebRequest rely on regular garbage collection ? [1]: https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.Dispose.html

UnityWebRequest error 0 in Editor, but not in WebGL build

$
0
0
I'm trying to send a UnityWebRequest to a server. It works perfectly on the WebGL Player, but not in the Editor private static IEnumerator SendWebRequest(UnityWebRequest webRequest, UnityAction doneAction) { using (webRequest) { yield return webRequest.Send(); if (webRequest.isError) { throw new Exception("Could not connect to backend: " + webRequest.responseCode); } doneAction(); } } In Editor, I simply dont receive anything from the server. The responseCode is 0. CORS has been set up accourdingly to the Unity Manual. I can get a response to other servers, e.g. www.google.com, it's just my server that is not working. Is there something else that needs to be configured in order for it to work?

How to change Host name in HttpWebRequest headers in unity .net 2.0?

$
0
0
I want to call a webpage by its ip address by adding custom values to request header for "host". "
" Code: HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://1.1.1.1"); request.Headers["Host"] = "xyz.net"; WebResponse response = request.GetResponse(); But it gives an error: **ArgumentException: restricted header** it seems that some headers cannot be modified in .net 2.0 so is there any way that i can change the host or change the .net version in unity to higher version?

UnityWebRequest behind a proxy

$
0
0
Hi

We have just released some software into schools. They all use proxy servers and I believe that this is preventing the UnityWebRequest from connecting properly to our web api.

The users can see the api in a web browser, but Unity seems unable to connect to it.

We had one school add a rule to their proxy to allow the API url and that sorted the problem, but we can't ask all the schools to do this.

Does anyone know of a way to make a Unity3D game UnityWebRequest work behind a proxy please?

Thank you!

Unable to call external API (IBM Watson) via HTTP request?

$
0
0
I'm trying to call IBM Watson's API to perform sentiment analysis from my Unity project, using the WWW library. This is my current code: string uri = "https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2017-02-27"; WWWForm form = new WWWForm(); form.AddField ("text", "That%20was%20simply%20magnificent!"); form.AddField ("features", "sentiment"); var headers = form.headers; byte[] rawData = form.data; headers["Authorization"] = "Basic " + System.Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(USERNAME + ":" + PASSWORD)); WWW www = new WWW(uri, rawData, headers); yield return www; where `USERNAME` and `PASSWORD` are my API credentials. However, this code keeps giving me a 415 error. Also, if I change `Authorization` to `Authentication`, the error changes to 401. I've tried making the same request using hurl.it (which works), and I've printed out the authorization header and compared it to what hurl.it constructs given a username and password, and they're the same string - yet the request fails in the project. What am I missing?

UnityWebRequest: strange responseCode values, eg -1202

$
0
0
We see a few HTTP requests come back with strange **responseCode**. I don't have a repro, so all i know is that when cast to an int (from a long), we sometimes get values like **-1202**, **-1200**, and **-1003** . [The docs][1] say that this value should either be a valid HTTP response code, or -1, or 0. Any clues ? [1]: https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest-responseCode.html

IOS HTTP GET with Authorization Header not being sent

$
0
0
Hi! I have got a problem connected to sending HTTP GET request with authorization header on iOS platform. In the editor and on Android it's fully working, but on iOS it is working nondeterministically. With POST there is no problem with sending header. I would really appreciate your feedback on this. Below I am attaching code for creating request: var www = UnityWebRequest.Get(url); www.timeout = timeout; foreach (var headerData in header) { www.SetRequestHeader(headerData.Key, headerData.Value); } and for creating request header: public Dictionary GetAuthorizationToken() { return new Dictionary { {"Authorization", "Bearer " + _userDataManager.UserData.AuthorizationToken} }; }

UnityWebRequest timeout not containing

$
0
0
I am trying to use Mapbox but I am receiving this error in the code provided in the SDK. namespace Mapbox.Unity.Utilities { using System; using UnityEngine.Networking; using System.Collections; using Mapbox.Platform; using UnityEngine; #if UNITY_EDITOR using UnityEditor; #endif internal sealed class HTTPRequest : IAsyncRequest { private UnityWebRequest _request; private readonly Action _callback; private UnityWebRequest timeout; public bool IsCompleted { get; private set; } public HTTPRequest(string url, Action callback, int timeout) { //UnityEngine.Debug.Log("HTTPRequest: " + url); IsCompleted = false; _request = UnityWebRequest.Get(url); _request.timeout = timeout; _callback = callback; Assets/Mapbox/Unity/Utilities/HTTPRequest.cs(33,13): error CS1061: Type `UnityEngine.Networking.UnityWebRequest' does not contain a definition for `timeout' and no extension method `timeout' of type `UnityEngine.Networking.UnityWebRequest' could be found. Are you missing an assembly reference? Can anyone help me solve this?

WWW class and UnityWebRequest no longer working in Unity 2017.3.0

$
0
0
Hi guys, I've been tasked with porting one of our apps from Unity 5.6.0 to Unity 2017.3.0. This app runs on the following platforms: - Windows Standalone - Windows Universal Store App - iOS - and Android So far, the Windows Standalone version works fine. The problems start with the Windows Univeral Store App version: With this platform I don't seem to be able to make any kind of http or https request. Previously when using Unity 5.6.0 we used the www class to make these requests. Here is a code snippet of the original code: if (Application.internetReachability != NetworkReachability.NotReachable) { // Construct header and append the encrypted XML string to the headers byte array. byte[] aRequest = AppendHeader(strXMLRequest); WWW cWWW = new WWW(m_strURL, aRequest); while (!cWWW.isDone) yield return null; try { m_strXMLResponse = cWWW.text; } catch { Debug.LogError("Download error!"); m_strXMLResponse = ""; } } This code no longer works under Windows Universal platform. `cWWW.text` is always empty. Now I realize that the `WWW` class is deprecated, so I decided to rewrite the code so it uses the `UnityWebRequest` class. Here is another short code snippet: UnityWebRequest uwr = UnityWebRequest.Post(m_strURL,""); yield return uwr.SendWebRequest(); if(uwr.isNetworkError) { Debug.Log("Error While sending: " + uwr.error); } else { Debug.Log("Received: " + uwr.downloadHandler.text); } However with this code `uwr.isNetworkError` is always `true` and `uwr.error` is always set to: "Generic/unknown http error." This is the case for any kind of http or https url. So at the moment ist seems I can not perform any kind of http or https request using unity classes in Unity version 2017.3.0. I downloaded Unity 5.6.0 again just to make sure it wasn't something to do with my computer or maybe some new settings that the sys admins made to the company firewall. - the code worked fine. Going back in Unity versions I could see that the code works up unitl Unity version 2017.2.1. So it would seem this is some kind of bug or regression within Unity 2017.3.0. I've tried all the patch versions of Unity 2017.3.0 and the 2018 Beta version and the problem persists in all these versions. Could someone please confirm if this is really an unintended bug and if there is some kind of workaround? If it is a Unity bug I would say this is very critical. Any help or feedback would be greatly appreciated. Cheers...

PATCH and DELETE methods - HTTP Requests problem

$
0
0
Hello ! I'm posting here today because I got a little problem. I have to make a Login menu in Unity. There is already an API, that I didn't make, I just have to send requests from Unity and analyze the responses. GET method is used to authenticate : GET /api/auth * *Request - first authentication (without token)* - `````` : (string) email address - `````` : (string) password I can use WWW class that supports GET method : IEnumerator Auth(){ string url = "127.0.0.1/api/auth?mail=" + mail + "&password=" + password; WWW www = new WWW(url); yield return www; if (!string.IsNullOrEmpty(www.error)){ Debug.Log(www.error); } else { Debug.Log(www.text); } } Tha't s working perfectly. To request a new pass, POST Method : **POST /api/passwordRenewal** * *Request* - `````` : email address I can use WWW class too : IEnumerator ResetPass(){ string url = "127.0.0.1/api/passwordRenewal"; WWWForm form = new WWWForm(); form.AddField("mail", mail); WWW www = new WWW(url, form); yield return www; if (!string.IsNullOrEmpty(www.error)){ Debug.Log(www.error); } else { Debug.Log(www.text); } } That's working perfectly too. Here is my problem : To change the password, PATCH method is used : **PATCH /api/auth** * *Request* - `````` : (string) new password - `````` : (string) current token But not supported by WWW class, so I searched and tried to use WebRequest class : public void ChangePass(){ string json = JsonUtility.ToJson(infos); // infos contains new_pw and old_token WebRequest request = WebRequest.Create ("http://127.0.0.1/api/auth"); request.Method = "PATCH"; byte[] byteArray = Encoding.UTF8.GetBytes (json); request.ContentType = "application/json"; request.ContentLength = byteArray.Length; Stream dataStream = request.GetRequestStream (); dataStream.Write (byteArray, 0, byteArray.Length); dataStream.Close (); WebResponse response = request.GetResponse (); Debug.Log(((HttpWebResponse)response).StatusDescription); dataStream = response.GetResponseStream (); StreamReader reader = new StreamReader (dataStream); string responseFromServer = reader.ReadToEnd (); Debug.Log(responseFromServer); reader.Close (); dataStream.Close (); response.Close (); } But I got a Bad Request (400), I don't really know how to use the PATCH method And to Logout, the DELETE method is used : **DELETE /api/auth** * *Request* - `````` : (string) token Here again I tried to use WebRequest class, but I don't know how to give the "token" information, I tried to "send it" but I got an error like "Can't send data with DELETE" And with the following code : public void Logout(){ string url = "http://127.0.0.1/api/auth"; WebRequest request = WebRequest.Create(url); request.Method = "DELETE"; WebResponse response = request.GetResponse(); } I got a bad request (400) I tried to pass the token in the url (?token=xxx) It still don't work. I never tried to send Http requests, and I don't know a lot about this, so I maybe missed important things ? If someone knows how I can solve my problem, that would be great ! (I'm new to c#, I started to use it 3 months ago when I started to use Unity ..) Thank you for your time !

HTTP GET Method in C# Unity 3D - How to target specific text or header

$
0
0
Hi everyone, I'm currently new here in Unity community so please go easy on me. I have problem with WebRequest in Unity its working but catches all html tags, meta date ext. So my question is is there a way to target specific text or image or header or something like that. Thanks in advance.

WWW yield is not returning any value in ios for yahoo finance api

$
0
0
Hi All, I am getting the stock value from yahoo finance and displaying it in a Text UI component. The below code is working fine in Windows PC, Mac, Android mobile but not in iOS. Code is not getting executed after " yield return wwwEricA;" only for yahoo finance http link "http://finance.yahoo.com/d/quotes.csv?s=ERIC-A.ST&f=sl1d1t1c1p2ohgv&e=.csv" . For testing i have given "https://www.google.co.in/" and that is returning value in ios mobile also. So i guess the problem is only with that particular yahoo URL but could not find what is that. Please help me to solve this issue. Code : public Text EricAStockText; private WWW wwwEricA; private string stockUrlEricA; private string[] stockArrayEricA; private char[] seperators = { ',' }; void Start() { stockUrlEricA = "http://finance.yahoo.com/d/quotes.csv?s=" + WWW.EscapeURL("ERIC-A.ST&f=sl1d1t1c1p2ohgv&e=.csv"); StartCoroutine(GetStockValueA(stockUrlEricA)); } private IEnumerator GetStockValueA(string URL) { wwwEricA = new WWW(URL); yield return wwwEricA; stockArrayEricA = ParseStockValue(wwwEricA.text, seperator); EricAStockText.text = stockArrayEricA[1]; } private string[] ParseStockValue(string valueString, char[] seperator) { return valueString.Split(seperator, System.StringSplitOptions.RemoveEmptyEntries); }

get a mysterious problem,when i use HttpWebRequest in unity c# script.

$
0
0
in script,i use HttpWebRequest to get service from network.but it comes a mysterious problem. the source code: string url = "http://apis.baidu.com/apistore/vop/baiduvopjson"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); print(request.Address); request.Method = "get"; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream s = response.GetResponseStream(); StreamReader Reader = new StreamReader(s, Encoding.UTF8); string strValue = ""; strValue = Reader.ReadToEnd(); print (strValue); the result is like(i have copy the html to a html file): ![alt text][1] [1]: /storage/temp/69776-1.jpg but the mysterious problem comes.when i use this code in Visual studio c# project,here is the source code: string url = "http://apis.baidu.com/apistore/vop/baiduvopjson"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "get"; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream s = response.GetResponseStream(); StreamReader Reader = new StreamReader(s, Encoding.UTF8); string strValue = ""; strValue = Reader.ReadToEnd(); Console.WriteLine(strValue); the result which is true in fact is as follows: {"errNum":300202,"errMsg":"Missing apikey"} do some one know what mistake do i make in unity project? why can i get the ture httpweb response?

How to stop mono from preventing authentication

$
0
0
Hi everyone! I am trying to connect to a server that requires a client certificate. I connect with httpWebRequest, and in a console App I made in Visual Sudio, it works like a charm! But when I try it in Unity, it doesn't work. (the 2 are identical) It throws me this TlsException at the GetResponse: > TlsException: The authentication or decryption has failed.> Mono.Security.Protocol.Tls.RecordProtocol.ProcessAlert (AlertLevel alertLevel, AlertDescription alertDesc)> Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult)> Rethrow as WebException: Error getting response stream (ReadDone1): ReceiveFailure> System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult)> System.Net.HttpWebRequest.GetResponse () So, from what I understand, the problem comes from Mono that prevent the authentication for some security reasons. Any idea how to override it? Here is the code used if it can help: ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(ValidateServerCertificate); X509Certificate2 clientCertificate = new X509Certificate2(path + ".p12", "password"); byte[] data = Encoding.ASCII.GetBytes("some data".ToCharArray()); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address); request.AuthenticationLevel = AuthenticationLevel.MutualAuthRequested; request.ClientCertificates.Add(clientCertificate); request.Method = "POST"; request.ContentType = "application/json"; request.ContentLength = data.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(data, 0, data.Length); dataStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); reader.Close(); dataStream.Close(); response.Close();
Viewing all 190 articles
Browse latest View live


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