BestHttpV3 实例代码
The world is changing, and I’m just trying to keep up. ----Arthur Morgan
实现功能:
- 发送请求
- 下载图片保存_阻塞式
- 下载图片保存——轮询式
- 下载小文件(图片),不保存
- 发送表单文件
插件导入
UniTask
https://github.com/Cysharp/UniTask
BestHttp v3,这个插件有v1,v2,v3版本,每个版本的文档都不相同!
https://assetstore.unity.com/packages/tools/network/best-http-267636

参考文档
//快速开始
//https://bestdocshub.pages.dev/HTTP/getting-started/#1-create-request
//BestHttp 总文档
//https://bestdocshub.pages.dev/
//测试网站
//httpbin.org
//文件下载部分的文档
//https://bestdocshub.pages.dev/HTTP/getting-started/downloads/#progress-tracking
//BestHttp v1的文档(过时)
//https://besthttp-documentation.readthedocs.io/en/dev/1.HTTP/HTTPRequest/
最佳实践代码
using Best.HTTP;
using Best.HTTP.Request.Upload.Forms;
using Best.HTTP.Response;
using Best.HTTP.Shared.PlatformSupport.Memory;
using Cysharp.Threading.Tasks;
using System;
using System.Buffers;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using UnityEngine;
public class BestHttp_ECode : MonoBehaviour
{
string tmp_postURL = "http://www.baidu.com";
private string path_bigFilePatg = "http://n.sinaimg.cn/sinacn/w480h306/20180118/6452-fyqtwzu4786357.jpg";
private string path_imageURL = "http://n.sinaimg.cn/sinacn/w480h306/20180118/6452-fyqtwzu4786357.jpg";
void Start()
{
StartCoroutine(nameof(Test_Get));
StartCoroutine(nameof(ShowPictureByHttpRequest));
StartCoroutine(nameof(Test_SendPost));
StartCoroutine(nameof(DownBigFile_WithBlicking));
StartCoroutine(nameof(Test_DownLoadABigFile_WithPolling));
}
private IEnumerator Test_Get()
{
HTTPRequest httpRequest = new HTTPRequest(new System.Uri(tmp_postURL), HTTPMethods.Get
, (request, response) =>
{
if (response.IsSuccess)
{
Debug.Log(response.DataAsText);
}
else
{
Debug.Log("发送失败");
}
});
httpRequest.Send();
yield return null;
}
/// <summary>
/// Post测试方法
/// </summary>
private IEnumerator Test_SendPost()
{
HTTPRequest tmp_post = new HTTPRequest(new System.Uri(tmp_postURL), HTTPMethods.Post,
(request, response) => { Debug.Log(response.DataAsText); });
yield return tmp_post.Send();
}
private IEnumerator AddFormData()
{
HTTPRequest tmp_post = new HTTPRequest(new System.Uri(tmp_postURL), HTTP

最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



