UnityHttpMessageHandler
An HttpMessageHandler that can be used with HttpClient to perform web requests using UnityWebRequest.
Read time 2 minutesLast updated 4 days ago
Definition
- Type: Class
- Namespace: UnityEngine.Networking
- Assembly: UnityEngine.UnityWebRequestModule
- Inherits from: HttpMessageHandler
- Implements: IDisposable
public sealed class UnityHttpMessageHandler : HttpMessageHandler, IDisposable
Remarks
UnityHttpMessageHandlerHttpClientHttpClientHttpMessageHandlerHttpClientUnityHttpMessageHandlerGrpcChannelIn a basic use case, can be used with to make HTTP requests.
UnityHttpMessageHandlerHttpClientExamples
using UnityEngine;using System.Net.Http;using UnityEngine.Networking;using Grpc.Core;using Grpc.Net.Client;public class GrpcChannelFactory{ public static GrpcChannel CreateGrpcChannel() { var httpHandler = new UnityEngine.Networking.UnityHttpMessageHandler() var channel = GrpcChannel.ForAddress("https://www.my-server.com", new GrpcChannelOptions { HttpHandler = httpHandler }); return channel; }}
using UnityEngine;using System.Net.Http;using UnityEngine.Networking;public class MyBehaviour : MonoBehaviour{ void Start() { DoRequestAsync(); } async void DoRequestAsync() { HttpClient client = new HttpClient(new UnityEngine.Networking.UnityHttpMessageHandler()); var request = new HttpRequestMessage(HttpMethod.Get, "https://www.my-server.com"); var response = await client.SendAsync(request); var status = response.StatusCode; var content = await response.Content.ReadAsStringAsync(); // content will contain the HTTP response body // Show results as text Debug.Log(content); }}
Constructors
Constructor | Description |
|---|---|
| UnityHttpMessageHandler() | Creates a |
Properties
Property | Description |
|---|---|
| CertificateHandler | Holds a reference to a UnityHttpMessageHandler.CertificateHandler object, which manages certificate validation for the underlying UnityWebRequest that this UnityHttpMessageHandler creates. |
| HttpForcedVersion | Force the version of HTTP used when making web requests with UnityHttpMessageHandler. |
Methods
Method | Description |
|---|---|
| SendAsync | Send an HTTP request as an asynchronous operation. |