网络通讯

comradexiao / 2024-11-12 / 原文

unity的请求类 UnityWebRequest

静态类创建(UnityWebRequest.Get())的Request是自带DownloadHandler和UploadHandler的
而构造创建(new UnityWebRequest() )是没有的,需要自己手动创建赋值,否则无法正常上传与接收数据

异常情况

.net实现服务器用于上传文件时,返回413错误提示上传文件过大

上传文件较大时,接收方需要做以下操作

image

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();

            services.Configure<FormOptions>(x =>
            {
                x.ValueLengthLimit = 2147483647;
                x.MultipartBodyLengthLimit = 2147483647; //2G
            });

        }

如果接收方使用的是iis则还需要做一下设置:

  1. 打开IIS,找到文件上传的项目,选中->功能试图->配置编辑器
    image

  2. 修改两处(httpRuntime、requestLimits )

    1. system.web/httpRuntimeexecutionTimeoutmaxRequestLength
      image

    2. system.webServer/security/requestFilteringrequestLimitsmaxAllowedContentLength
      image