com.xmobitea.changx.gn-unity 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Editor/GNServerSettingsEditor.cs +294 -294
- package/Runtime/Config/GNServerSettings.cs +5 -9
- package/Runtime/Constant/EnumType/MatchmakingMemberStatus.cs.meta +11 -11
- package/Runtime/Constant/EnumType/MatchmakingTicketStatus.cs.meta +11 -11
- package/Runtime/Entity/DataMember.cs +1 -1
- package/Runtime/Entity/Models/MultiplayerModels.cs.meta +11 -11
- package/Runtime/Entity/Models/MultiplayerRequestModels.cs.meta +11 -11
- package/Runtime/Entity/Models/MultiplayerResponseModels.cs.meta +11 -11
- package/Runtime/GNNetworkMultiplayerApi.cs.meta +11 -11
- package/Runtime/Helper/ConverterService.cs +41 -12
- package/Runtime/Networking/Http/HttpPeer.cs +6 -2
- package/Runtime/Networking/Http/NetworkingPeerHttpClientRequest.cs +480 -363
- package/Runtime/Networking/Http/NetworkingPeerHttpRequest.cs +3 -68
- package/Runtime/Networking/Http/NetworkingPeerUnityWebRequest.cs +5 -1
- package/package.json +1 -1
|
@@ -1,373 +1,490 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
//
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
//
|
|
88
|
-
//
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
//
|
|
92
|
-
//
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
//
|
|
96
|
-
//
|
|
97
|
-
|
|
98
|
-
//
|
|
99
|
-
//
|
|
100
|
-
//
|
|
101
|
-
//
|
|
102
|
-
|
|
103
|
-
//
|
|
104
|
-
//
|
|
105
|
-
//
|
|
106
|
-
//
|
|
107
|
-
//
|
|
108
|
-
|
|
109
|
-
//
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
//
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
//
|
|
119
|
-
|
|
120
|
-
//
|
|
121
|
-
|
|
122
|
-
//
|
|
123
|
-
|
|
124
|
-
//
|
|
125
|
-
|
|
126
|
-
//
|
|
127
|
-
|
|
128
|
-
//
|
|
129
|
-
|
|
130
|
-
//
|
|
131
|
-
//
|
|
132
|
-
|
|
133
|
-
//
|
|
134
|
-
//
|
|
135
|
-
//
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
//
|
|
202
|
-
//
|
|
203
|
-
//
|
|
204
|
-
|
|
205
|
-
//
|
|
206
|
-
//
|
|
207
|
-
//
|
|
208
|
-
//
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
//
|
|
212
|
-
//
|
|
213
|
-
//
|
|
214
|
-
//
|
|
215
|
-
|
|
216
|
-
//
|
|
217
|
-
|
|
218
|
-
//
|
|
219
|
-
|
|
220
|
-
//
|
|
221
|
-
//
|
|
222
|
-
//
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
//
|
|
228
|
-
|
|
229
|
-
//
|
|
230
|
-
|
|
231
|
-
//
|
|
232
|
-
//
|
|
233
|
-
//
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
//
|
|
239
|
-
|
|
240
|
-
//
|
|
241
|
-
//
|
|
242
|
-
|
|
243
|
-
//
|
|
244
|
-
//
|
|
245
|
-
|
|
246
|
-
//
|
|
247
|
-
|
|
248
|
-
//
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
//
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
//
|
|
255
|
-
//
|
|
256
|
-
//
|
|
257
|
-
//
|
|
258
|
-
//
|
|
259
|
-
//
|
|
260
|
-
|
|
261
|
-
//
|
|
262
|
-
//
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
//
|
|
266
|
-
//
|
|
267
|
-
//
|
|
268
|
-
//
|
|
269
|
-
//
|
|
270
|
-
|
|
271
|
-
//
|
|
272
|
-
|
|
273
|
-
//
|
|
274
|
-
|
|
275
|
-
//
|
|
276
|
-
//
|
|
277
|
-
|
|
278
|
-
//
|
|
1
|
+
namespace XmobiTea.GN.Networking.Http
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using System.Net;
|
|
5
|
+
using System.Net.Http;
|
|
6
|
+
using System.Text;
|
|
7
|
+
using XmobiTea.GN.Common;
|
|
8
|
+
using XmobiTea.GN.Constant;
|
|
9
|
+
using XmobiTea.GN.Helper;
|
|
10
|
+
using XmobiTea.MsgPack;
|
|
11
|
+
|
|
12
|
+
internal class NetworkingPeerHttpWebRequest : NetworkingHttpPeerBase
|
|
13
|
+
{
|
|
14
|
+
private readonly HttpClient client;
|
|
15
|
+
|
|
16
|
+
//private static string POST = "POST";
|
|
17
|
+
//private static string GET = "GET";
|
|
18
|
+
|
|
19
|
+
public override void getRequest(string subUri, Action<HttpAppResponse> onHttpAppResponse, float timeout, string authToken, string secretKey)
|
|
20
|
+
{
|
|
21
|
+
this.getRequestViaHttpWeb(subUri, onHttpAppResponse, timeout, authToken, secretKey);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private async void getRequestViaHttpWeb(string subUri, Action<HttpAppResponse> onHttpAppResponse, float timeout, string authToken, string secretKey)
|
|
25
|
+
{
|
|
26
|
+
using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, this.httpUrl + "/" + subUri))
|
|
27
|
+
{
|
|
28
|
+
if (!string.IsNullOrEmpty(authToken)) requestMessage.Headers.Add(Commands.RequestAuthTokenCmd, authToken);
|
|
29
|
+
if (!string.IsNullOrEmpty(secretKey)) requestMessage.Headers.Add(Commands.RequestSecretCmd, secretKey);
|
|
30
|
+
|
|
31
|
+
try
|
|
32
|
+
{
|
|
33
|
+
var webResponse = await this.client.SendAsync(requestMessage);
|
|
34
|
+
|
|
35
|
+
var httpAppResponse = new HttpAppResponse();
|
|
36
|
+
httpAppResponse.statusCode = (int)webResponse.StatusCode;
|
|
37
|
+
|
|
38
|
+
if (webResponse.StatusCode == HttpStatusCode.OK)
|
|
39
|
+
{
|
|
40
|
+
httpAppResponse.data = await webResponse.Content.ReadAsByteArrayAsync();
|
|
41
|
+
httpAppResponse.text = await webResponse.Content.ReadAsStringAsync();
|
|
42
|
+
}
|
|
43
|
+
else
|
|
44
|
+
{
|
|
45
|
+
httpAppResponse.error = webResponse.ReasonPhrase;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
onHttpAppResponse?.Invoke(httpAppResponse);
|
|
49
|
+
}
|
|
50
|
+
catch (Exception e)
|
|
51
|
+
{
|
|
52
|
+
var httpAppResponse = new HttpAppResponse();
|
|
53
|
+
|
|
54
|
+
httpAppResponse.statusCode = -1;
|
|
55
|
+
httpAppResponse.error = e.Message;
|
|
56
|
+
|
|
57
|
+
onHttpAppResponse?.Invoke(httpAppResponse);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//private async void getRequestViaHttpWeb(string subUri, Action<HttpAppResponse> onHttpAppResponse, float timeout, string authToken, string secretKey)
|
|
63
|
+
//{
|
|
64
|
+
// try
|
|
65
|
+
// {
|
|
66
|
+
// var httpRequest = (HttpWebRequest)WebRequest.Create(this.httpUrl + "/" + subUri);
|
|
67
|
+
// httpRequest.UserAgent = this.userAgent;
|
|
68
|
+
// httpRequest.SendChunked = false;
|
|
69
|
+
// // Prevents hitting a proxy if no proxy is available. TODO: Add support for proxy's.
|
|
70
|
+
// httpRequest.Proxy = null;
|
|
71
|
+
|
|
72
|
+
// httpRequest.Method = NetworkingPeerHttpWebRequest.GET;
|
|
73
|
+
// httpRequest.KeepAlive = false;
|
|
74
|
+
// httpRequest.Timeout = (int)timeout;
|
|
75
|
+
// httpRequest.ReadWriteTimeout = (int)timeout;
|
|
76
|
+
|
|
77
|
+
// if (!string.IsNullOrEmpty(authToken)) httpRequest.Headers.Add(Commands.RequestAuthTokenCmd, authToken);
|
|
78
|
+
// if (!string.IsNullOrEmpty(secretKey)) httpRequest.Headers.Add(Commands.RequestSecretCmd, secretKey);
|
|
79
|
+
|
|
80
|
+
// var response = await httpRequest.GetResponseAsync();
|
|
81
|
+
|
|
82
|
+
// var webResponse = (HttpWebResponse)response;
|
|
83
|
+
|
|
84
|
+
// var httpAppResponse = new HttpAppResponse();
|
|
85
|
+
// httpAppResponse.statusCode = (int)webResponse.StatusCode;
|
|
86
|
+
|
|
87
|
+
// if (webResponse.StatusCode == HttpStatusCode.OK)
|
|
88
|
+
// {
|
|
89
|
+
// using (var responseStream = webResponse.GetResponseStream())
|
|
90
|
+
// {
|
|
91
|
+
// using (var memoryStream = new MemoryStream())
|
|
92
|
+
// {
|
|
93
|
+
// responseStream.CopyTo(memoryStream);
|
|
94
|
+
|
|
95
|
+
// httpAppResponse.data = memoryStream.ToArray();
|
|
96
|
+
// }
|
|
97
|
+
|
|
98
|
+
// using (var stream = new StreamReader(responseStream))
|
|
99
|
+
// {
|
|
100
|
+
// httpAppResponse.text = stream.ReadToEnd();
|
|
101
|
+
// }
|
|
102
|
+
// }
|
|
103
|
+
// }
|
|
104
|
+
// else
|
|
105
|
+
// {
|
|
106
|
+
// httpAppResponse.error = webResponse.StatusDescription;
|
|
107
|
+
// }
|
|
108
|
+
|
|
109
|
+
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
110
|
+
// }
|
|
111
|
+
// catch (WebException e)
|
|
112
|
+
// {
|
|
113
|
+
// var httpAppResponse = new HttpAppResponse();
|
|
114
|
+
|
|
115
|
+
// httpAppResponse.statusCode = -1;
|
|
116
|
+
|
|
117
|
+
// using (var stream = new StreamReader(e.Response.GetResponseStream()))
|
|
118
|
+
// {
|
|
119
|
+
// httpAppResponse.error = stream.ReadToEnd();
|
|
120
|
+
// }
|
|
121
|
+
|
|
122
|
+
// if (string.IsNullOrEmpty(httpAppResponse.error)) httpAppResponse.error = e.Message;
|
|
123
|
+
|
|
124
|
+
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
125
|
+
// }
|
|
126
|
+
// catch (Exception e)
|
|
127
|
+
// {
|
|
128
|
+
// var httpAppResponse = new HttpAppResponse();
|
|
129
|
+
|
|
130
|
+
// httpAppResponse.statusCode = -1;
|
|
131
|
+
// httpAppResponse.error = e.Message;
|
|
132
|
+
|
|
133
|
+
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
134
|
+
// }
|
|
135
|
+
//}
|
|
136
|
+
|
|
137
|
+
public override void postRequest(string subUri, GNHashtable param, PostType postType, Action<HttpAppResponse> onHttpAppResponse, float timeout, string authToken, string secretKey, GNHashtable customTags)
|
|
138
|
+
{
|
|
139
|
+
this.postRequestViaHttpWeb(subUri, param, postType, onHttpAppResponse, timeout, authToken, secretKey, customTags);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private async void postRequestViaHttpWeb(string subUri, GNHashtable param, PostType postType, Action<HttpAppResponse> onHttpAppResponse, float timeout, string authToken, string secretKey, GNHashtable customTags)
|
|
143
|
+
{
|
|
144
|
+
using (var requestMessage = new HttpRequestMessage(HttpMethod.Post, this.httpUrl + "/" + subUri))
|
|
145
|
+
{
|
|
146
|
+
if (param == null) param = new GNHashtable();
|
|
147
|
+
|
|
148
|
+
if (customTags != null) param.add(GNParameterCode.CustomTags, customTags);
|
|
149
|
+
|
|
150
|
+
if (postType == PostType.Json)
|
|
151
|
+
{
|
|
152
|
+
var content = Encoding.UTF8.GetBytes(Serializer.Serialize(param.toData()));
|
|
153
|
+
|
|
154
|
+
requestMessage.Content = new ByteArrayContent(content);
|
|
155
|
+
|
|
156
|
+
requestMessage.Headers.TryAddWithoutValidation(Commands.CONTENT_TYPE, Commands.APPLICATION_JSON);
|
|
157
|
+
}
|
|
158
|
+
else if (postType == PostType.MsgPack)
|
|
159
|
+
{
|
|
160
|
+
var content = MsgPackSerializer.Serialize(param.toData());
|
|
161
|
+
|
|
162
|
+
requestMessage.Content = new ByteArrayContent(content);
|
|
163
|
+
|
|
164
|
+
requestMessage.Headers.TryAddWithoutValidation(Commands.CONTENT_TYPE, Commands.APPLICATION_MSGPACK);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (!string.IsNullOrEmpty(authToken)) requestMessage.Headers.TryAddWithoutValidation(Commands.RequestAuthTokenCmd, authToken);
|
|
168
|
+
if (!string.IsNullOrEmpty(secretKey)) requestMessage.Headers.TryAddWithoutValidation(Commands.RequestSecretCmd, secretKey);
|
|
169
|
+
|
|
170
|
+
try
|
|
171
|
+
{
|
|
172
|
+
var webResponse = await this.client.SendAsync(requestMessage);
|
|
173
|
+
|
|
174
|
+
var httpAppResponse = new HttpAppResponse();
|
|
175
|
+
httpAppResponse.statusCode = (int)webResponse.StatusCode;
|
|
176
|
+
|
|
177
|
+
if (webResponse.StatusCode == HttpStatusCode.OK)
|
|
178
|
+
{
|
|
179
|
+
httpAppResponse.data = await webResponse.Content.ReadAsByteArrayAsync();
|
|
180
|
+
httpAppResponse.text = await webResponse.Content.ReadAsStringAsync();
|
|
181
|
+
}
|
|
182
|
+
else
|
|
183
|
+
{
|
|
184
|
+
httpAppResponse.error = webResponse.ReasonPhrase;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
onHttpAppResponse?.Invoke(httpAppResponse);
|
|
188
|
+
}
|
|
189
|
+
catch (Exception e)
|
|
190
|
+
{
|
|
191
|
+
var httpAppResponse = new HttpAppResponse();
|
|
192
|
+
|
|
193
|
+
httpAppResponse.statusCode = -1;
|
|
194
|
+
httpAppResponse.error = e.Message;
|
|
195
|
+
|
|
196
|
+
onHttpAppResponse?.Invoke(httpAppResponse);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
//private async void postRequestViaHttpWeb(string subUri, GNHashtable param, PostType postType, Action<HttpAppResponse> onHttpAppResponse, float timeout, string authToken, string secretKey, GNHashtable customTags)
|
|
202
|
+
//{
|
|
203
|
+
// try
|
|
204
|
+
// {
|
|
205
|
+
// var httpRequest = (HttpWebRequest)WebRequest.Create(this.httpUrl + "/" + subUri);
|
|
206
|
+
// httpRequest.UserAgent = this.userAgent;
|
|
207
|
+
// httpRequest.SendChunked = false;
|
|
208
|
+
// // Prevents hitting a proxy if no proxy is available. TODO: Add support for proxy's.
|
|
209
|
+
// httpRequest.Proxy = null;
|
|
210
|
+
|
|
211
|
+
// httpRequest.Method = NetworkingPeerHttpWebRequest.POST;
|
|
212
|
+
// httpRequest.KeepAlive = false;
|
|
213
|
+
// httpRequest.Timeout = (int)timeout;
|
|
214
|
+
// httpRequest.ReadWriteTimeout = (int)timeout;
|
|
215
|
+
|
|
216
|
+
// if (param == null) param = new GNHashtable();
|
|
217
|
+
|
|
218
|
+
// if (customTags != null) param.add(GNParameterCode.CustomTags, customTags);
|
|
219
|
+
|
|
220
|
+
// if (postType == PostType.Json)
|
|
221
|
+
// {
|
|
222
|
+
// httpRequest.Headers.Add(Commands.CONTENT_TYPE, Commands.APPLICATION_JSON);
|
|
223
|
+
|
|
224
|
+
// var content = Encoding.UTF8.GetBytes(Serializer.Serialize(param.toData()));
|
|
225
|
+
|
|
226
|
+
// using (var stream = httpRequest.GetRequestStream())
|
|
227
|
+
// {
|
|
228
|
+
// stream.Write(content, 0, content.Length);
|
|
229
|
+
// }
|
|
230
|
+
// }
|
|
231
|
+
// else if (postType == PostType.MsgPack)
|
|
232
|
+
// {
|
|
233
|
+
// httpRequest.Headers.Add(Commands.CONTENT_TYPE, Commands.APPLICATION_MSGPACK);
|
|
234
|
+
|
|
235
|
+
// var content = MsgPackSerializer.Serialize(param.toData());
|
|
236
|
+
|
|
237
|
+
// using (var stream = httpRequest.GetRequestStream())
|
|
238
|
+
// {
|
|
239
|
+
// stream.Write(content, 0, content.Length);
|
|
240
|
+
// }
|
|
241
|
+
// }
|
|
242
|
+
|
|
243
|
+
// if (!string.IsNullOrEmpty(authToken)) httpRequest.Headers.Add(Commands.RequestAuthTokenCmd, authToken);
|
|
244
|
+
// if (!string.IsNullOrEmpty(secretKey)) httpRequest.Headers.Add(Commands.RequestSecretCmd, secretKey);
|
|
245
|
+
|
|
246
|
+
// var response = await httpRequest.GetResponseAsync();
|
|
247
|
+
|
|
248
|
+
// var webResponse = (HttpWebResponse)response;
|
|
249
|
+
|
|
250
|
+
// var httpAppResponse = new HttpAppResponse();
|
|
251
|
+
// httpAppResponse.statusCode = (int)webResponse.StatusCode;
|
|
252
|
+
|
|
253
|
+
// if (webResponse.StatusCode == HttpStatusCode.OK)
|
|
254
|
+
// {
|
|
255
|
+
// using (var responseStream = webResponse.GetResponseStream())
|
|
256
|
+
// {
|
|
257
|
+
// using (var memoryStream = new MemoryStream())
|
|
258
|
+
// {
|
|
259
|
+
// responseStream.CopyTo(memoryStream);
|
|
260
|
+
|
|
261
|
+
// httpAppResponse.data = memoryStream.ToArray();
|
|
262
|
+
// }
|
|
263
|
+
|
|
264
|
+
// using (var stream = new StreamReader(responseStream))
|
|
265
|
+
// {
|
|
266
|
+
// httpAppResponse.text = stream.ReadToEnd();
|
|
267
|
+
// }
|
|
268
|
+
// }
|
|
269
|
+
// }
|
|
270
|
+
// else
|
|
271
|
+
// {
|
|
272
|
+
// httpAppResponse.error = webResponse.StatusDescription;
|
|
273
|
+
// }
|
|
274
|
+
|
|
275
|
+
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
276
|
+
// }
|
|
277
|
+
// catch (WebException e)
|
|
278
|
+
// {
|
|
279
|
+
// var httpAppResponse = new HttpAppResponse();
|
|
280
|
+
|
|
281
|
+
// httpAppResponse.statusCode = -1;
|
|
282
|
+
|
|
283
|
+
// using (var stream = new StreamReader(e.Response.GetResponseStream()))
|
|
284
|
+
// {
|
|
285
|
+
// httpAppResponse.error = stream.ReadToEnd();
|
|
286
|
+
// }
|
|
287
|
+
|
|
288
|
+
// if (string.IsNullOrEmpty(httpAppResponse.error)) httpAppResponse.error = e.Message;
|
|
289
|
+
|
|
290
|
+
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
291
|
+
// }
|
|
292
|
+
// catch (Exception e)
|
|
293
|
+
// {
|
|
294
|
+
// var httpAppResponse = new HttpAppResponse();
|
|
295
|
+
|
|
296
|
+
// httpAppResponse.statusCode = -1;
|
|
297
|
+
// httpAppResponse.error = e.Message;
|
|
298
|
+
|
|
299
|
+
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
300
|
+
// }
|
|
301
|
+
//}
|
|
302
|
+
|
|
303
|
+
public override void postRequestUpload(string subUri, byte[] content, string mimetype, Action<HttpAppResponse> onHttpAppResponse, float timeout)
|
|
304
|
+
{
|
|
305
|
+
this.postRequestUploadViaHttpWeb(subUri, content, mimetype, onHttpAppResponse, timeout);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
private async void postRequestUploadViaHttpWeb(string subUri, byte[] content, string mimetype, Action<HttpAppResponse> onHttpAppResponse, float timeout)
|
|
309
|
+
{
|
|
310
|
+
//try
|
|
311
|
+
//{
|
|
312
|
+
// var httpRequest = (HttpWebRequest)WebRequest.Create(this.httpUrl + "/" + subUri);
|
|
313
|
+
// httpRequest.UserAgent = this.userAgent;
|
|
314
|
+
// httpRequest.SendChunked = false;
|
|
315
|
+
// // Prevents hitting a proxy if no proxy is available. TODO: Add support for proxy's.
|
|
316
|
+
// httpRequest.Proxy = null;
|
|
317
|
+
|
|
318
|
+
// httpRequest.Method = NetworkingPeerHttpWebRequest.POST;
|
|
319
|
+
// httpRequest.KeepAlive = false;
|
|
320
|
+
// httpRequest.Timeout = (int)timeout;
|
|
321
|
+
// httpRequest.ReadWriteTimeout = (int)timeout;
|
|
322
|
+
|
|
323
|
+
// var authToken = GNNetwork.getAuthenticateStatus().getAuthToken();
|
|
324
|
+
|
|
325
|
+
// if (!string.IsNullOrEmpty(authToken)) httpRequest.Headers.Add(Commands.RequestAuthTokenCmd, authToken);
|
|
326
|
+
|
|
327
|
+
// var headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n" + "Content-Type: application/octet-stream\r\n\r\n";
|
|
328
|
+
|
|
329
|
+
// using (var stream = httpRequest.GetRequestStream())
|
|
330
|
+
// {
|
|
331
|
+
// stream.Write(content, 0, content.Length);
|
|
332
|
+
// }
|
|
333
|
+
|
|
334
|
+
// var response = await httpRequest.GetResponseAsync();
|
|
335
|
+
|
|
336
|
+
// var webResponse = (HttpWebResponse)response;
|
|
337
|
+
|
|
338
|
+
// var httpAppResponse = new HttpAppResponse();
|
|
339
|
+
// httpAppResponse.statusCode = (int)webResponse.StatusCode;
|
|
340
|
+
|
|
341
|
+
// if (webResponse.StatusCode == HttpStatusCode.OK)
|
|
342
|
+
// {
|
|
343
|
+
// using (var responseStream = webResponse.GetResponseStream())
|
|
344
|
+
// {
|
|
345
|
+
// using (var memoryStream = new MemoryStream())
|
|
346
|
+
// {
|
|
347
|
+
// responseStream.CopyTo(memoryStream);
|
|
348
|
+
|
|
349
|
+
// httpAppResponse.data = memoryStream.ToArray();
|
|
350
|
+
// }
|
|
351
|
+
|
|
352
|
+
// using (var stream = new StreamReader(responseStream))
|
|
353
|
+
// {
|
|
354
|
+
// httpAppResponse.text = stream.ReadToEnd();
|
|
355
|
+
// }
|
|
356
|
+
// }
|
|
357
|
+
// }
|
|
358
|
+
// else
|
|
359
|
+
// {
|
|
360
|
+
// httpAppResponse.error = webResponse.StatusDescription;
|
|
361
|
+
// }
|
|
362
|
+
|
|
363
|
+
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
364
|
+
//}
|
|
365
|
+
//catch (WebException e)
|
|
366
|
+
//{
|
|
367
|
+
// var httpAppResponse = new HttpAppResponse();
|
|
368
|
+
|
|
369
|
+
// httpAppResponse.statusCode = -1;
|
|
370
|
+
|
|
371
|
+
// using (var stream = new StreamReader(e.Response.GetResponseStream()))
|
|
372
|
+
// {
|
|
373
|
+
// httpAppResponse.error = stream.ReadToEnd();
|
|
374
|
+
// }
|
|
375
|
+
|
|
376
|
+
// if (string.IsNullOrEmpty(httpAppResponse.error)) httpAppResponse.error = e.Message;
|
|
377
|
+
|
|
378
|
+
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
379
|
+
//}
|
|
380
|
+
//catch (Exception e)
|
|
381
|
+
//{
|
|
382
|
+
// var httpAppResponse = new HttpAppResponse();
|
|
383
|
+
|
|
384
|
+
// httpAppResponse.statusCode = -1;
|
|
385
|
+
// httpAppResponse.error = e.Message;
|
|
386
|
+
|
|
387
|
+
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
388
|
+
//}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
//private async void postRequestUploadViaHttpWeb(string subUri, byte[] content, string mimetype, Action<HttpAppResponse> onHttpAppResponse, float timeout)
|
|
392
|
+
//{
|
|
393
|
+
// try
|
|
394
|
+
// {
|
|
395
|
+
// var httpRequest = (HttpWebRequest)WebRequest.Create(this.httpUrl + "/" + subUri);
|
|
396
|
+
// httpRequest.UserAgent = this.userAgent;
|
|
397
|
+
// httpRequest.SendChunked = false;
|
|
398
|
+
// // Prevents hitting a proxy if no proxy is available. TODO: Add support for proxy's.
|
|
399
|
+
// httpRequest.Proxy = null;
|
|
400
|
+
|
|
401
|
+
// httpRequest.Method = NetworkingPeerHttpWebRequest.POST;
|
|
402
|
+
// httpRequest.KeepAlive = false;
|
|
403
|
+
// httpRequest.Timeout = (int)timeout;
|
|
404
|
+
// httpRequest.ReadWriteTimeout = (int)timeout;
|
|
405
|
+
|
|
406
|
+
// var authToken = GNNetwork.getAuthenticateStatus().getAuthToken();
|
|
407
|
+
|
|
408
|
+
// if (!string.IsNullOrEmpty(authToken)) httpRequest.Headers.Add(Commands.RequestAuthTokenCmd, authToken);
|
|
409
|
+
|
|
410
|
+
// var headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n" + "Content-Type: application/octet-stream\r\n\r\n";
|
|
411
|
+
|
|
412
|
+
// using (var stream = httpRequest.GetRequestStream())
|
|
413
|
+
// {
|
|
414
|
+
// stream.Write(content, 0, content.Length);
|
|
415
|
+
// }
|
|
279
416
|
|
|
280
|
-
//
|
|
281
|
-
|
|
282
|
-
//
|
|
283
|
-
// {
|
|
284
|
-
// var httpAppResponse = new HttpAppResponse();
|
|
285
|
-
|
|
286
|
-
// httpAppResponse.statusCode = -1;
|
|
287
|
-
// httpAppResponse.error = e.Message;
|
|
417
|
+
// var response = await httpRequest.GetResponseAsync();
|
|
418
|
+
|
|
419
|
+
// var webResponse = (HttpWebResponse)response;
|
|
288
420
|
|
|
289
|
-
//
|
|
290
|
-
//
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
//
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
421
|
+
// var httpAppResponse = new HttpAppResponse();
|
|
422
|
+
// httpAppResponse.statusCode = (int)webResponse.StatusCode;
|
|
423
|
+
|
|
424
|
+
// if (webResponse.StatusCode == HttpStatusCode.OK)
|
|
425
|
+
// {
|
|
426
|
+
// using (var responseStream = webResponse.GetResponseStream())
|
|
427
|
+
// {
|
|
428
|
+
// using (var memoryStream = new MemoryStream())
|
|
429
|
+
// {
|
|
430
|
+
// responseStream.CopyTo(memoryStream);
|
|
431
|
+
|
|
432
|
+
// httpAppResponse.data = memoryStream.ToArray();
|
|
433
|
+
// }
|
|
434
|
+
|
|
435
|
+
// using (var stream = new StreamReader(responseStream))
|
|
436
|
+
// {
|
|
437
|
+
// httpAppResponse.text = stream.ReadToEnd();
|
|
438
|
+
// }
|
|
439
|
+
// }
|
|
440
|
+
// }
|
|
441
|
+
// else
|
|
442
|
+
// {
|
|
443
|
+
// httpAppResponse.error = webResponse.StatusDescription;
|
|
444
|
+
// }
|
|
445
|
+
|
|
446
|
+
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
447
|
+
// }
|
|
448
|
+
// catch (WebException e)
|
|
449
|
+
// {
|
|
450
|
+
// var httpAppResponse = new HttpAppResponse();
|
|
451
|
+
|
|
452
|
+
// httpAppResponse.statusCode = -1;
|
|
453
|
+
|
|
454
|
+
// using (var stream = new StreamReader(e.Response.GetResponseStream()))
|
|
455
|
+
// {
|
|
456
|
+
// httpAppResponse.error = stream.ReadToEnd();
|
|
457
|
+
// }
|
|
458
|
+
|
|
459
|
+
// if (string.IsNullOrEmpty(httpAppResponse.error)) httpAppResponse.error = e.Message;
|
|
297
460
|
|
|
298
|
-
//
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
// // httpRequest.UserAgent = this.userAgent;
|
|
304
|
-
// // httpRequest.SendChunked = false;
|
|
305
|
-
// // // Prevents hitting a proxy if no proxy is available. TODO: Add support for proxy's.
|
|
306
|
-
// // httpRequest.Proxy = null;
|
|
461
|
+
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
462
|
+
// }
|
|
463
|
+
// catch (Exception e)
|
|
464
|
+
// {
|
|
465
|
+
// var httpAppResponse = new HttpAppResponse();
|
|
307
466
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
// // httpRequest.Method = "POST";
|
|
312
|
-
// // httpRequest.KeepAlive = false;
|
|
313
|
-
// // httpRequest.Timeout = (int)timeout;
|
|
314
|
-
// // httpRequest.AllowWriteStreamBuffering = false;
|
|
315
|
-
// // httpRequest.Proxy = null;
|
|
316
|
-
// // httpRequest.ReadWriteTimeout = (int)timeout;
|
|
467
|
+
// httpAppResponse.statusCode = -1;
|
|
468
|
+
// httpAppResponse.error = e.Message;
|
|
317
469
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
470
|
+
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
471
|
+
// }
|
|
472
|
+
//}
|
|
321
473
|
|
|
322
|
-
|
|
474
|
+
public override void init(string httpUrl, string userAgent)
|
|
475
|
+
{
|
|
476
|
+
base.init(httpUrl, userAgent);
|
|
323
477
|
|
|
324
|
-
|
|
478
|
+
this.client.DefaultRequestHeaders.TryAddWithoutValidation(Commands.USER_AGENT, userAgent);
|
|
479
|
+
}
|
|
325
480
|
|
|
326
|
-
|
|
481
|
+
public NetworkingPeerHttpWebRequest()
|
|
482
|
+
{
|
|
483
|
+
//HTTPManager.KeepAliveDefaultValue = true;
|
|
327
484
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
// // }
|
|
333
|
-
// // else if (postType == PostType.MsgPack)
|
|
334
|
-
// // {
|
|
335
|
-
// // httpRequest.ContentType = Commands.APPLICATION_MSGPACK;
|
|
485
|
+
this.client = new HttpClient();
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
}
|
|
336
489
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
// // var content = MsgPackSerializer.Serialize(dataSend);
|
|
340
|
-
|
|
341
|
-
// // httpRequest.ContentLength = content.LongLength;
|
|
342
|
-
|
|
343
|
-
// // using (var stream = httpRequest.GetRequestStream())
|
|
344
|
-
// // {
|
|
345
|
-
// // stream.Write(content, 0, content.Length);
|
|
346
|
-
// // }
|
|
347
|
-
// // }
|
|
348
|
-
|
|
349
|
-
// // var response = await httpRequest.GetResponseAsync();
|
|
350
|
-
|
|
351
|
-
// // response.
|
|
352
|
-
// // }
|
|
353
|
-
// // catch (Exception e)
|
|
354
|
-
// // {
|
|
355
|
-
|
|
356
|
-
// // }
|
|
357
|
-
// //}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
// public override void init(string httpUrl, string userAgent)
|
|
361
|
-
// {
|
|
362
|
-
// base.init(httpUrl, userAgent);
|
|
363
|
-
// }
|
|
364
|
-
|
|
365
|
-
// public NetworkingPeerHttpWebRequest()
|
|
366
|
-
// {
|
|
367
|
-
// //HTTPManager.KeepAliveDefaultValue = true;
|
|
368
|
-
// }
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
// }
|
|
372
|
-
|
|
373
|
-
//}
|
|
490
|
+
}
|