DownloadHandlerBuffer
A general-purpose DownloadHandler implementation which stores received data in a native byte buffer.
Read time 1 minuteLast updated 4 days ago
Definition
- Type: Class
- Namespace: UnityEngine.Networking
- Assembly: UnityEngine.UnityWebRequestModule
- Inherits from: DownloadHandler
- Implements: IDisposable
public sealed class DownloadHandlerBuffer : DownloadHandler, IDisposable
Remarks
This is a general-purpose DownloadHandler subclass. It stores received data in native memory. It preallocates a data buffer based on any received header, but expands its buffer if the actual download size exceeds the value of the header (or if a header is not received).
Content-LengthContent-LengthContent-LengthNote: When accessing _data or _text on this subclass, a new byte array or string is allocated each time the property is accessed.
Examples
using UnityEngine;using UnityEngine.Networking;using System.Collections;public class MyBehaviour : MonoBehaviour { void Start() { StartCoroutine(GetText()); } IEnumerator GetText() { UnityWebRequest www = new UnityWebRequest("https://www.my-server.com"); www.downloadHandler = new DownloadHandlerBuffer(); yield return www.SendWebRequest(); if (www.result != UnityWebRequest.Result.Success) { 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; } }}
Constructors
Constructor | Description |
|---|---|
| DownloadHandlerBuffer() | Default constructor. |
Static Methods
Method | Description |
|---|---|
| GetContent | Returns a copy of the native-memory buffer interpreted as a UTF8 string. |