Skip to content

Commit 216ee49

Browse files
committed
feat(Web): 为二进制请求添加内容类型头
添加 BinaryContentType 常量并设置二进制请求的 Content-Type 头,确保服务器能正确识别二进制数据格式
1 parent dc499bd commit 216ee49

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

Runtime/Web/WebManager.Binary.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public partial class WebManager : GameFrameworkModule, IWebManager
2828
/// </summary>
2929
private readonly List<WebBinaryData> m_SendingBinaryList = new List<WebBinaryData>(16);
3030

31+
/// <summary>
32+
/// Binary内容类型常量
33+
/// </summary>
34+
private const string BinaryContentType = "application/octet-stream";
35+
3136
/// <summary>
3237
/// 更新处理ProtoBuf请求队列
3338
/// </summary>
@@ -94,6 +99,7 @@ private async void MakeBinaryBytesRequest(WebBinaryData webData)
9499

95100
unityWebRequest.timeout = (int)RequestTimeout.TotalSeconds;
96101
{
102+
unityWebRequest.SetRequestHeader("Content-Type", BinaryContentType);
97103
byte[] postData = webData.SendData;
98104
unityWebRequest.uploadHandler = new UploadHandlerRaw(postData);
99105
}
@@ -116,6 +122,7 @@ private async void MakeBinaryBytesRequest(WebBinaryData webData)
116122
HttpWebRequest request = WebRequest.CreateHttp(webData.URL);
117123
request.Method = webData.IsGet ? WebRequestMethods.Http.Get : WebRequestMethods.Http.Post;
118124
request.Timeout = (int)RequestTimeout.TotalMilliseconds; // 设置请求超时时间
125+
request.ContentType = BinaryContentType;
119126
byte[] postData = webData.SendData;
120127
request.ContentLength = postData.Length;
121128
using (Stream requestStream = request.GetRequestStream())
@@ -157,6 +164,7 @@ private async void MakeBinaryBytesRequest(WebBinaryData webData)
157164
{
158165
m_SendingBinaryList.Remove(webData);
159166
}
167+
160168
#endif
161169
}
162170

0 commit comments

Comments
 (0)