注意:已弃用 UNet,未来会将其从 Unity 中删除。一个新系统正在开发中。如需了解更多信息和后续步骤,请参阅此博客文章以及常见问题解答 (FAQ)。 |
目前,仅一种类型的上传处理程序可用:UploadHandlerRaw
。此类在构建时接受数据缓冲区。此缓冲区在内部复制到本机代码内存中,然后当远程服务器准备好接受主体数据时,此缓冲区由 UnityWebRequest
系统使用。
上传处理程序还接受“Content Type”字符串。如果在 UnityWebRequest 自身中没有设置 Content-Type
标头,则此字符串用于 UnityWebRequest 的 Content-Type
标头值。如果在 UnityWebRequest 对象上手动设置了 Content-Type
标头,则将忽略上传处理程序对象上的 Content-Type
。
如果没有在 UnityWebRequest 或 UploadHandler
上设置 Content-Type
,则系统会将 Content-Type
默认设置为 application/octet-stream
。
UnityWebRequest
具有一个 disposeUploadHandlerOnDispose
属性,其默认值为 true。如果此属性为 true,则在处理 UnityWebRequest 对象时还将在附加的上传处理程序上调用 Dispose(),致使下载处理程序无用。如果保持对上传处理程序的引用时间长度超过对 UnityWebRequest 的引用时间长度,应将 disposeUploadHandlerOnDispose 设置为 false。
byte[] payload = new byte[1024];
// ...使用数据填充有效负载 ...
UnityWebRequest wr = new UnityWebRequest("http://www.mysite.com/data-upload");
UploadHandler uploader = new UploadHandlerRaw(payload);
// 发送标头:"Content-Type: custom/content-type";
uploader.contentType = "custom/content-type";
wr.uploadHandler = uploader;
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.