- Home /
Image display from IP camera
I want to output an image from an IP camera via HTTP communication, but it does not work. 401errror is output. Here is the code:
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
using UnityEngine.UI;
public class TestCamera : MonoBehaviour
{
void Start()
{
StartCoroutine(makeRequest());
}
string authenticate(string username, string password)
{
string auth = username + ":" + password;
auth = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(auth));
auth = "Basic " + auth;
return auth;
}
IEnumerator makeRequest()
{
string authorization = authenticate("id", "password");
string url = "http://ipaddress/axis-cgi/jpg/image.cgi";
UnityWebRequest www = UnityWebRequestTexture.GetTexture(url);
www.SetRequestHeader("AUTHORIZATION", authorization);
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
Texture texture = ((DownloadHandlerTexture)www.downloadHandler).texture;
RawImage img = gameObject.GetComponent<RawImage>();
img.texture = texture;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Instantiated object not showing in scene or hierarchy 2 Answers
,How to stop jump animtion 1 Answer
How to add a score when the correct object drags to the correct box? 1 Answer