Unity Web Request Creating Upload Handlers
Send request body data to a server using the UploadHandlerRaw and UploadHandlerFile upload handlers.
阅读时间2 分钟最后更新于 1 个月前
目前有两种类型的上传处理程序可用: 和 。
UploadHandlerRawUploadHandlerFileUploadHandlerRawUnityWebRequestNativeArrayUploadHandlerFile上传处理程序还接受“Content Type”字符串。如果在 UnityWebRequest 自身中没有设置 标头,则此字符串用于 UnityWebRequest 的 标头值。如果在 UnityWebRequest 对象上手动设置了 标头,则将忽略上传处理程序对象上的 。
Content-TypeContent-TypeContent-TypeContent-Type如果没有在 UnityWebRequest 或 上设置 ,则系统会将 默认设置为 。
UploadHandlerContent-TypeContent-Typeapplication/octet-streamUnityWebRequestdisposeUploadHandlerOnDispose示例
byte[] payload = new byte[1024];// ... fill payload with data ...UnityWebRequest wr = new UnityWebRequest("https://www.mysite.com/data-upload");UploadHandler uploader = new UploadHandlerRaw(payload);// Sends header: "Content-Type: custom/content-type";uploader.contentType = "custom/content-type";wr.uploadHandler = uploader;