com.xmobitea.changx.gn-unity 2.0.1 → 2.0.3
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 +27 -23
- package/Runtime/Common/GNArray.cs +302 -302
- package/Runtime/Common/GNArray.cs.meta +11 -11
- package/Runtime/Common/GNData.cs +48 -48
- package/Runtime/Common/GNData.cs.meta +11 -11
- package/Runtime/Common/GNHashtable.cs +241 -241
- package/Runtime/Common/GNHashtable.cs.meta +11 -11
- package/Runtime/Common/IGNData.cs +11 -11
- package/Runtime/Common/IGNData.cs.meta +11 -11
- package/Runtime/Common.meta +8 -8
- package/Runtime/Config/GNServerSettings.cs.meta +11 -11
- package/Runtime/Config.meta +8 -8
- package/Runtime/Constant/Commands.cs.meta +11 -11
- package/Runtime/Constant/EnumType/FriendStatus.cs +12 -12
- package/Runtime/Constant/EnumType/FriendStatus.cs.meta +11 -11
- package/Runtime/Constant/EnumType/GoogleLoginType.cs.meta +11 -11
- package/Runtime/Constant/EnumType/GroupStatus.cs.meta +11 -11
- package/Runtime/Constant/EnumType/InvalidMemberType.cs +23 -23
- package/Runtime/Constant/EnumType/InvalidMemberType.cs.meta +11 -11
- package/Runtime/Constant/EnumType/ItemType.cs.meta +11 -11
- package/Runtime/Constant/EnumType/MatchmakingMemberStatus.cs.meta +11 -11
- package/Runtime/Constant/EnumType/MatchmakingTicketStatus.cs.meta +11 -11
- package/Runtime/Constant/EnumType/OwnerType.cs.meta +11 -11
- package/Runtime/Constant/EnumType/PermissionDataItem.cs +10 -10
- package/Runtime/Constant/EnumType/PermissionDataItem.cs.meta +11 -11
- package/Runtime/Constant/EnumType/RequestRole.cs +11 -11
- package/Runtime/Constant/EnumType/RequestRole.cs.meta +7 -7
- package/Runtime/Constant/EnumType/RequestType.cs +19 -19
- package/Runtime/Constant/EnumType/RequestType.cs.meta +11 -11
- package/Runtime/Constant/EnumType.meta +8 -8
- package/Runtime/Constant/ErrorCode/GNErrorCode.cs.meta +7 -7
- package/Runtime/Constant/ErrorCode.meta +8 -8
- package/Runtime/Constant/EventCode.cs +16 -16
- package/Runtime/Constant/EventCode.cs.meta +11 -11
- package/Runtime/Constant/OperationCode.cs.meta +11 -11
- package/Runtime/Constant/ParameterCode/GNParameterCode.cs.meta +11 -11
- package/Runtime/Constant/ParameterCode/ParameterCode.cs +12 -12
- package/Runtime/Constant/ParameterCode/ParameterCode.cs.meta +11 -11
- package/Runtime/Constant/ParameterCode.meta +8 -8
- package/Runtime/Constant/ReturnCode.cs +25 -25
- package/Runtime/Constant/ReturnCode.cs.meta +11 -11
- package/Runtime/Constant.meta +8 -8
- package/Runtime/Entity/DataMember.cs +124 -124
- package/Runtime/Entity/DataMember.cs.meta +11 -11
- package/Runtime/Entity/GNMetadata.cs +27 -27
- package/Runtime/Entity/GNMetadata.cs.meta +11 -11
- package/Runtime/Entity/InvalidMember.cs +33 -33
- package/Runtime/Entity/InvalidMember.cs.meta +11 -11
- package/Runtime/Entity/Models/AuthenticateModels.cs.meta +11 -11
- package/Runtime/Entity/Models/AuthenticateRequestModels.cs.meta +11 -11
- package/Runtime/Entity/Models/AuthenticateResponseModels.cs.meta +11 -11
- package/Runtime/Entity/Models/CharacterPlayerModels.cs.meta +11 -11
- package/Runtime/Entity/Models/CharacterPlayerRequestModels.cs.meta +11 -11
- package/Runtime/Entity/Models/CharacterPlayerResponseModels.cs.meta +11 -11
- package/Runtime/Entity/Models/ContentModels.cs.meta +11 -11
- package/Runtime/Entity/Models/ContentRequestModels.cs.meta +11 -11
- package/Runtime/Entity/Models/ContentResponseModels.cs.meta +11 -11
- package/Runtime/Entity/Models/DashboardModels.cs.meta +11 -11
- package/Runtime/Entity/Models/DashboardRequestModels.cs.meta +11 -11
- package/Runtime/Entity/Models/DashboardResponseModels.cs.meta +11 -11
- package/Runtime/Entity/Models/GamePlayerModels.cs.meta +11 -11
- package/Runtime/Entity/Models/GamePlayerRequestModels.cs.meta +11 -11
- package/Runtime/Entity/Models/GamePlayerResponseModels.cs.meta +11 -11
- package/Runtime/Entity/Models/GenericModels.cs.meta +11 -11
- package/Runtime/Entity/Models/GroupModels.cs.meta +11 -11
- package/Runtime/Entity/Models/GroupRequestModels.cs.meta +11 -11
- package/Runtime/Entity/Models/GroupResponseModels.cs.meta +11 -11
- package/Runtime/Entity/Models/InventoryModels.cs.meta +11 -11
- package/Runtime/Entity/Models/InventoryRequestModels.cs.meta +11 -11
- package/Runtime/Entity/Models/InventoryResponseModels.cs.meta +11 -11
- package/Runtime/Entity/Models/MasterPlayerModels.cs.meta +11 -11
- package/Runtime/Entity/Models/MasterPlayerRequestModels.cs.meta +11 -11
- package/Runtime/Entity/Models/MasterPlayerResponseModels.cs.meta +11 -11
- package/Runtime/Entity/Models/MultiplayerModels.cs.meta +11 -11
- package/Runtime/Entity/Models/MultiplayerRequestModels.cs.meta +11 -11
- package/Runtime/Entity/Models/MultiplayerResponseModels.cs +49 -49
- package/Runtime/Entity/Models/MultiplayerResponseModels.cs.meta +11 -11
- package/Runtime/Entity/Models/StoreInventoryModels.cs.meta +11 -11
- package/Runtime/Entity/Models/StoreInventoryRequestModels.cs.meta +11 -11
- package/Runtime/Entity/Models/StoreInventoryResponseModels.cs.meta +11 -11
- package/Runtime/Entity/Models.meta +8 -8
- package/Runtime/Entity/OperationEvent.cs +75 -75
- package/Runtime/Entity/OperationEvent.cs.meta +11 -11
- package/Runtime/Entity/OperationHelper.cs +35 -35
- package/Runtime/Entity/OperationHelper.cs.meta +11 -11
- package/Runtime/Entity/OperationRequest.cs +99 -99
- package/Runtime/Entity/OperationRequest.cs.meta +11 -11
- package/Runtime/Entity/OperationResponse.cs.meta +11 -11
- package/Runtime/Entity/Request/CustomOperationRequest.cs +61 -61
- package/Runtime/Entity/Request/CustomOperationRequest.cs.meta +11 -11
- package/Runtime/Entity/Request.meta +8 -8
- package/Runtime/Entity/Response/CustomOperationResponse.cs +63 -63
- package/Runtime/Entity/Response/CustomOperationResponse.cs.meta +11 -11
- package/Runtime/Entity/Response.meta +8 -8
- package/Runtime/Entity.meta +8 -8
- package/Runtime/GNNetwork.cs +182 -184
- package/Runtime/GNNetwork.cs.meta +11 -11
- package/Runtime/GNNetworkApi.cs +19 -26
- package/Runtime/GNNetworkApi.cs.meta +11 -11
- package/Runtime/GNNetworkAuthenticateApi.cs.meta +11 -11
- package/Runtime/GNNetworkCharacterPlayerApi.cs.meta +11 -11
- package/Runtime/GNNetworkContentApi.cs.meta +11 -11
- package/Runtime/GNNetworkDashboardApi.cs.meta +11 -11
- package/Runtime/GNNetworkGamePlayerApi.cs.meta +11 -11
- package/Runtime/GNNetworkGroupApi.cs.meta +11 -11
- package/Runtime/GNNetworkInventoryApi.cs.meta +11 -11
- package/Runtime/GNNetworkMasterPlayerApi.cs.meta +11 -11
- package/Runtime/GNNetworkMultiplayerApi.cs.meta +11 -11
- package/Runtime/GNNetworkStoreInventoryApi.cs.meta +11 -11
- package/Runtime/Helper/CodeHelper.cs +97 -97
- package/Runtime/Helper/CodeHelper.cs.meta +11 -11
- package/Runtime/Helper/ConverterService.cs +12 -22
- package/Runtime/Helper/ConverterService.cs.meta +11 -11
- package/Runtime/Helper/ParseGNHelper.cs +451 -451
- package/Runtime/Helper/ParseGNHelper.cs.meta +11 -11
- package/Runtime/Helper.meta +8 -8
- package/Runtime/Logger/GNDebug.cs +49 -49
- package/Runtime/Logger/GNDebug.cs.meta +11 -11
- package/Runtime/Logger.meta +8 -8
- package/Runtime/Networking/AuthenticateStatus.cs +35 -35
- package/Runtime/Networking/AuthenticateStatus.cs.meta +11 -11
- package/Runtime/Networking/Handler/IServerEventHandler.cs +25 -25
- package/Runtime/Networking/Handler/IServerEventHandler.cs.meta +11 -11
- package/Runtime/Networking/Handler/OnCharacterPlayerFriendUpdateEventHandler.cs +32 -32
- package/Runtime/Networking/Handler/OnCharacterPlayerFriendUpdateEventHandler.cs.meta +11 -11
- package/Runtime/Networking/Handler/OnCharacterPlayerGroupUpdateEventHandler.cs +33 -33
- package/Runtime/Networking/Handler/OnCharacterPlayerGroupUpdateEventHandler.cs.meta +11 -11
- package/Runtime/Networking/Handler/OnGamePlayerFriendUpdateEventHandler.cs +32 -32
- package/Runtime/Networking/Handler/OnGamePlayerFriendUpdateEventHandler.cs.meta +11 -11
- package/Runtime/Networking/Handler/OnGamePlayerGroupUpdateEventHandler.cs +32 -32
- package/Runtime/Networking/Handler/OnGamePlayerGroupUpdateEventHandler.cs.meta +11 -11
- package/Runtime/Networking/Handler/OnGroupMemberUpdateEventHandler.cs +29 -29
- package/Runtime/Networking/Handler/OnGroupMemberUpdateEventHandler.cs.meta +11 -11
- package/Runtime/Networking/Handler/OnGroupMessageUpdateEventHandler.cs +29 -29
- package/Runtime/Networking/Handler/OnGroupMessageUpdateEventHandler.cs.meta +11 -11
- package/Runtime/Networking/Handler.meta +8 -8
- package/Runtime/Networking/Http/HttpPeer.cs.meta +11 -11
- package/Runtime/Networking/Http/NetworkingHttpPeerBase.cs +25 -25
- package/Runtime/Networking/Http/NetworkingHttpPeerBase.cs.meta +11 -11
- package/Runtime/Networking/Http/NetworkingPeerHttpClientRequest.cs +486 -486
- package/Runtime/Networking/Http/NetworkingPeerHttpClientRequest.cs.meta +11 -11
- package/Runtime/Networking/Http/NetworkingPeerHttpRequest.cs +142 -142
- package/Runtime/Networking/Http/NetworkingPeerHttpRequest.cs.meta +11 -11
- package/Runtime/Networking/Http/NetworkingPeerUnityWebRequest.cs +188 -192
- package/Runtime/Networking/Http/NetworkingPeerUnityWebRequest.cs.meta +11 -11
- package/Runtime/Networking/Http.meta +8 -8
- package/Runtime/Networking/IPeer.cs +19 -19
- package/Runtime/Networking/IPeer.cs.meta +11 -11
- package/Runtime/Networking/NetworkingPeer.cs +144 -144
- package/Runtime/Networking/NetworkingPeer.cs.meta +11 -11
- package/Runtime/Networking/NetworkingPeerAPI.cs.meta +11 -11
- package/Runtime/Networking/OperationPending.cs +95 -95
- package/Runtime/Networking/OperationPending.cs.meta +11 -11
- package/Runtime/Networking/PeerBase.cs +242 -242
- package/Runtime/Networking/PeerBase.cs.meta +11 -11
- package/Runtime/Networking/Socket/NetworkingPeerSocketV2.cs +185 -183
- package/Runtime/Networking/Socket/NetworkingPeerSocketV2.cs.meta +11 -11
- package/Runtime/Networking/Socket/NetworkingPeerSocketV3.cs +177 -175
- package/Runtime/Networking/Socket/NetworkingPeerSocketV3.cs.meta +11 -11
- package/Runtime/Networking/Socket/NetworkingSocketPeerBase.cs.meta +11 -11
- package/Runtime/Networking/Socket/SocketPeer.cs +197 -191
- package/Runtime/Networking/Socket/SocketPeer.cs.meta +11 -11
- package/Runtime/Networking/Socket.meta +8 -8
- package/Runtime/Networking.meta +8 -8
- package/Runtime/Unity/ServiceUpdate.cs +20 -20
- package/Runtime/Unity/ServiceUpdate.cs.meta +11 -11
- package/Runtime/Unity.meta +8 -8
- package/Runtime/XmobiTea.GN.runtime.asmdef +16 -16
- package/Runtime/XmobiTea.GN.runtime.asmdef.meta +7 -7
- package/package.json +1 -1
|
@@ -1,486 +1,486 @@
|
|
|
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
|
-
|
|
153
|
-
var content = Encoding.UTF8.GetBytes(Serializer.Serialize(param.toData()));
|
|
154
|
-
|
|
155
|
-
requestMessage.Content = new ByteArrayContent(content);
|
|
156
|
-
|
|
157
|
-
requestMessage.Headers.Add(Commands.CONTENT_TYPE, Commands.APPLICATION_JSON);
|
|
158
|
-
}
|
|
159
|
-
else if (postType == PostType.MsgPack)
|
|
160
|
-
{
|
|
161
|
-
|
|
162
|
-
var content = MsgPackSerializer.Serialize(param.toData());
|
|
163
|
-
|
|
164
|
-
requestMessage.Content = new ByteArrayContent(content);
|
|
165
|
-
|
|
166
|
-
requestMessage.Headers.Add(Commands.CONTENT_TYPE, Commands.APPLICATION_MSGPACK);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
if (!string.IsNullOrEmpty(authToken)) requestMessage.Headers.Add(Commands.RequestAuthTokenCmd, authToken);
|
|
170
|
-
if (!string.IsNullOrEmpty(secretKey)) requestMessage.Headers.Add(Commands.RequestSecretCmd, secretKey);
|
|
171
|
-
|
|
172
|
-
try
|
|
173
|
-
{
|
|
174
|
-
var webResponse = await this.client.SendAsync(requestMessage);
|
|
175
|
-
|
|
176
|
-
var httpAppResponse = new HttpAppResponse();
|
|
177
|
-
httpAppResponse.statusCode = (int)webResponse.StatusCode;
|
|
178
|
-
|
|
179
|
-
if (webResponse.StatusCode == HttpStatusCode.OK)
|
|
180
|
-
{
|
|
181
|
-
httpAppResponse.data = await webResponse.Content.ReadAsByteArrayAsync();
|
|
182
|
-
httpAppResponse.text = await webResponse.Content.ReadAsStringAsync();
|
|
183
|
-
}
|
|
184
|
-
else
|
|
185
|
-
{
|
|
186
|
-
httpAppResponse.error = webResponse.ReasonPhrase;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
onHttpAppResponse?.Invoke(httpAppResponse);
|
|
190
|
-
}
|
|
191
|
-
catch (Exception e)
|
|
192
|
-
{
|
|
193
|
-
var httpAppResponse = new HttpAppResponse();
|
|
194
|
-
|
|
195
|
-
httpAppResponse.statusCode = -1;
|
|
196
|
-
httpAppResponse.error = e.Message;
|
|
197
|
-
|
|
198
|
-
onHttpAppResponse?.Invoke(httpAppResponse);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
//private async void postRequestViaHttpWeb(string subUri, GNHashtable param, PostType postType, Action<HttpAppResponse> onHttpAppResponse, float timeout, string authToken, string secretKey, GNHashtable customTags)
|
|
204
|
-
//{
|
|
205
|
-
// try
|
|
206
|
-
// {
|
|
207
|
-
// var httpRequest = (HttpWebRequest)WebRequest.Create(this.httpUrl + "/" + subUri);
|
|
208
|
-
// httpRequest.UserAgent = this.userAgent;
|
|
209
|
-
// httpRequest.SendChunked = false;
|
|
210
|
-
// // Prevents hitting a proxy if no proxy is available. TODO: Add support for proxy's.
|
|
211
|
-
// httpRequest.Proxy = null;
|
|
212
|
-
|
|
213
|
-
// httpRequest.Method = NetworkingPeerHttpWebRequest.POST;
|
|
214
|
-
// httpRequest.KeepAlive = false;
|
|
215
|
-
// httpRequest.Timeout = (int)timeout;
|
|
216
|
-
// httpRequest.ReadWriteTimeout = (int)timeout;
|
|
217
|
-
|
|
218
|
-
// if (param == null) param = new GNHashtable();
|
|
219
|
-
|
|
220
|
-
// if (customTags != null) param.add(GNParameterCode.CustomTags, customTags);
|
|
221
|
-
|
|
222
|
-
// if (postType == PostType.Json)
|
|
223
|
-
// {
|
|
224
|
-
// httpRequest.Headers.Add(Commands.CONTENT_TYPE, Commands.APPLICATION_JSON);
|
|
225
|
-
|
|
226
|
-
// var content = Encoding.UTF8.GetBytes(Serializer.Serialize(param.toData()));
|
|
227
|
-
|
|
228
|
-
// using (var stream = httpRequest.GetRequestStream())
|
|
229
|
-
// {
|
|
230
|
-
// stream.Write(content, 0, content.Length);
|
|
231
|
-
// }
|
|
232
|
-
// }
|
|
233
|
-
// else if (postType == PostType.MsgPack)
|
|
234
|
-
// {
|
|
235
|
-
// httpRequest.Headers.Add(Commands.CONTENT_TYPE, Commands.APPLICATION_MSGPACK);
|
|
236
|
-
|
|
237
|
-
// var content = MsgPackSerializer.Serialize(param.toData());
|
|
238
|
-
|
|
239
|
-
// using (var stream = httpRequest.GetRequestStream())
|
|
240
|
-
// {
|
|
241
|
-
// stream.Write(content, 0, content.Length);
|
|
242
|
-
// }
|
|
243
|
-
// }
|
|
244
|
-
|
|
245
|
-
// if (!string.IsNullOrEmpty(authToken)) httpRequest.Headers.Add(Commands.RequestAuthTokenCmd, authToken);
|
|
246
|
-
// if (!string.IsNullOrEmpty(secretKey)) httpRequest.Headers.Add(Commands.RequestSecretCmd, secretKey);
|
|
247
|
-
|
|
248
|
-
// var response = await httpRequest.GetResponseAsync();
|
|
249
|
-
|
|
250
|
-
// var webResponse = (HttpWebResponse)response;
|
|
251
|
-
|
|
252
|
-
// var httpAppResponse = new HttpAppResponse();
|
|
253
|
-
// httpAppResponse.statusCode = (int)webResponse.StatusCode;
|
|
254
|
-
|
|
255
|
-
// if (webResponse.StatusCode == HttpStatusCode.OK)
|
|
256
|
-
// {
|
|
257
|
-
// using (var responseStream = webResponse.GetResponseStream())
|
|
258
|
-
// {
|
|
259
|
-
// using (var memoryStream = new MemoryStream())
|
|
260
|
-
// {
|
|
261
|
-
// responseStream.CopyTo(memoryStream);
|
|
262
|
-
|
|
263
|
-
// httpAppResponse.data = memoryStream.ToArray();
|
|
264
|
-
// }
|
|
265
|
-
|
|
266
|
-
// using (var stream = new StreamReader(responseStream))
|
|
267
|
-
// {
|
|
268
|
-
// httpAppResponse.text = stream.ReadToEnd();
|
|
269
|
-
// }
|
|
270
|
-
// }
|
|
271
|
-
// }
|
|
272
|
-
// else
|
|
273
|
-
// {
|
|
274
|
-
// httpAppResponse.error = webResponse.StatusDescription;
|
|
275
|
-
// }
|
|
276
|
-
|
|
277
|
-
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
278
|
-
// }
|
|
279
|
-
// catch (WebException e)
|
|
280
|
-
// {
|
|
281
|
-
// var httpAppResponse = new HttpAppResponse();
|
|
282
|
-
|
|
283
|
-
// httpAppResponse.statusCode = -1;
|
|
284
|
-
|
|
285
|
-
// using (var stream = new StreamReader(e.Response.GetResponseStream()))
|
|
286
|
-
// {
|
|
287
|
-
// httpAppResponse.error = stream.ReadToEnd();
|
|
288
|
-
// }
|
|
289
|
-
|
|
290
|
-
// if (string.IsNullOrEmpty(httpAppResponse.error)) httpAppResponse.error = e.Message;
|
|
291
|
-
|
|
292
|
-
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
293
|
-
// }
|
|
294
|
-
// catch (Exception e)
|
|
295
|
-
// {
|
|
296
|
-
// var httpAppResponse = new HttpAppResponse();
|
|
297
|
-
|
|
298
|
-
// httpAppResponse.statusCode = -1;
|
|
299
|
-
// httpAppResponse.error = e.Message;
|
|
300
|
-
|
|
301
|
-
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
302
|
-
// }
|
|
303
|
-
//}
|
|
304
|
-
|
|
305
|
-
public override void postRequestUpload(string subUri, byte[] content, string mimetype, Action<HttpAppResponse> onHttpAppResponse, float timeout)
|
|
306
|
-
{
|
|
307
|
-
this.postRequestUploadViaHttpWeb(subUri, content, mimetype, onHttpAppResponse, timeout);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
private async void postRequestUploadViaHttpWeb(string subUri, byte[] content, string mimetype, Action<HttpAppResponse> onHttpAppResponse, float timeout)
|
|
311
|
-
{
|
|
312
|
-
//try
|
|
313
|
-
//{
|
|
314
|
-
// var httpRequest = (HttpWebRequest)WebRequest.Create(this.httpUrl + "/" + subUri);
|
|
315
|
-
// httpRequest.UserAgent = this.userAgent;
|
|
316
|
-
// httpRequest.SendChunked = false;
|
|
317
|
-
// // Prevents hitting a proxy if no proxy is available. TODO: Add support for proxy's.
|
|
318
|
-
// httpRequest.Proxy = null;
|
|
319
|
-
|
|
320
|
-
// httpRequest.Method = NetworkingPeerHttpWebRequest.POST;
|
|
321
|
-
// httpRequest.KeepAlive = false;
|
|
322
|
-
// httpRequest.Timeout = (int)timeout;
|
|
323
|
-
// httpRequest.ReadWriteTimeout = (int)timeout;
|
|
324
|
-
|
|
325
|
-
// var authToken = GNNetwork.getAuthenticateStatus().getAuthToken();
|
|
326
|
-
|
|
327
|
-
// if (!string.IsNullOrEmpty(authToken)) httpRequest.Headers.Add(Commands.RequestAuthTokenCmd, authToken);
|
|
328
|
-
|
|
329
|
-
// var headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n" + "Content-Type: application/octet-stream\r\n\r\n";
|
|
330
|
-
|
|
331
|
-
// using (var stream = httpRequest.GetRequestStream())
|
|
332
|
-
// {
|
|
333
|
-
// stream.Write(content, 0, content.Length);
|
|
334
|
-
// }
|
|
335
|
-
|
|
336
|
-
// var response = await httpRequest.GetResponseAsync();
|
|
337
|
-
|
|
338
|
-
// var webResponse = (HttpWebResponse)response;
|
|
339
|
-
|
|
340
|
-
// var httpAppResponse = new HttpAppResponse();
|
|
341
|
-
// httpAppResponse.statusCode = (int)webResponse.StatusCode;
|
|
342
|
-
|
|
343
|
-
// if (webResponse.StatusCode == HttpStatusCode.OK)
|
|
344
|
-
// {
|
|
345
|
-
// using (var responseStream = webResponse.GetResponseStream())
|
|
346
|
-
// {
|
|
347
|
-
// using (var memoryStream = new MemoryStream())
|
|
348
|
-
// {
|
|
349
|
-
// responseStream.CopyTo(memoryStream);
|
|
350
|
-
|
|
351
|
-
// httpAppResponse.data = memoryStream.ToArray();
|
|
352
|
-
// }
|
|
353
|
-
|
|
354
|
-
// using (var stream = new StreamReader(responseStream))
|
|
355
|
-
// {
|
|
356
|
-
// httpAppResponse.text = stream.ReadToEnd();
|
|
357
|
-
// }
|
|
358
|
-
// }
|
|
359
|
-
// }
|
|
360
|
-
// else
|
|
361
|
-
// {
|
|
362
|
-
// httpAppResponse.error = webResponse.StatusDescription;
|
|
363
|
-
// }
|
|
364
|
-
|
|
365
|
-
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
366
|
-
//}
|
|
367
|
-
//catch (WebException e)
|
|
368
|
-
//{
|
|
369
|
-
// var httpAppResponse = new HttpAppResponse();
|
|
370
|
-
|
|
371
|
-
// httpAppResponse.statusCode = -1;
|
|
372
|
-
|
|
373
|
-
// using (var stream = new StreamReader(e.Response.GetResponseStream()))
|
|
374
|
-
// {
|
|
375
|
-
// httpAppResponse.error = stream.ReadToEnd();
|
|
376
|
-
// }
|
|
377
|
-
|
|
378
|
-
// if (string.IsNullOrEmpty(httpAppResponse.error)) httpAppResponse.error = e.Message;
|
|
379
|
-
|
|
380
|
-
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
381
|
-
//}
|
|
382
|
-
//catch (Exception e)
|
|
383
|
-
//{
|
|
384
|
-
// var httpAppResponse = new HttpAppResponse();
|
|
385
|
-
|
|
386
|
-
// httpAppResponse.statusCode = -1;
|
|
387
|
-
// httpAppResponse.error = e.Message;
|
|
388
|
-
|
|
389
|
-
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
390
|
-
//}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
//private async void postRequestUploadViaHttpWeb(string subUri, byte[] content, string mimetype, Action<HttpAppResponse> onHttpAppResponse, float timeout)
|
|
394
|
-
//{
|
|
395
|
-
// try
|
|
396
|
-
// {
|
|
397
|
-
// var httpRequest = (HttpWebRequest)WebRequest.Create(this.httpUrl + "/" + subUri);
|
|
398
|
-
// httpRequest.UserAgent = this.userAgent;
|
|
399
|
-
// httpRequest.SendChunked = false;
|
|
400
|
-
// // Prevents hitting a proxy if no proxy is available. TODO: Add support for proxy's.
|
|
401
|
-
// httpRequest.Proxy = null;
|
|
402
|
-
|
|
403
|
-
// httpRequest.Method = NetworkingPeerHttpWebRequest.POST;
|
|
404
|
-
// httpRequest.KeepAlive = false;
|
|
405
|
-
// httpRequest.Timeout = (int)timeout;
|
|
406
|
-
// httpRequest.ReadWriteTimeout = (int)timeout;
|
|
407
|
-
|
|
408
|
-
// var authToken = GNNetwork.getAuthenticateStatus().getAuthToken();
|
|
409
|
-
|
|
410
|
-
// if (!string.IsNullOrEmpty(authToken)) httpRequest.Headers.Add(Commands.RequestAuthTokenCmd, authToken);
|
|
411
|
-
|
|
412
|
-
// var headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n" + "Content-Type: application/octet-stream\r\n\r\n";
|
|
413
|
-
|
|
414
|
-
// using (var stream = httpRequest.GetRequestStream())
|
|
415
|
-
// {
|
|
416
|
-
// stream.Write(content, 0, content.Length);
|
|
417
|
-
// }
|
|
418
|
-
|
|
419
|
-
// var response = await httpRequest.GetResponseAsync();
|
|
420
|
-
|
|
421
|
-
// var webResponse = (HttpWebResponse)response;
|
|
422
|
-
|
|
423
|
-
// var httpAppResponse = new HttpAppResponse();
|
|
424
|
-
// httpAppResponse.statusCode = (int)webResponse.StatusCode;
|
|
425
|
-
|
|
426
|
-
// if (webResponse.StatusCode == HttpStatusCode.OK)
|
|
427
|
-
// {
|
|
428
|
-
// using (var responseStream = webResponse.GetResponseStream())
|
|
429
|
-
// {
|
|
430
|
-
// using (var memoryStream = new MemoryStream())
|
|
431
|
-
// {
|
|
432
|
-
// responseStream.CopyTo(memoryStream);
|
|
433
|
-
|
|
434
|
-
// httpAppResponse.data = memoryStream.ToArray();
|
|
435
|
-
// }
|
|
436
|
-
|
|
437
|
-
// using (var stream = new StreamReader(responseStream))
|
|
438
|
-
// {
|
|
439
|
-
// httpAppResponse.text = stream.ReadToEnd();
|
|
440
|
-
// }
|
|
441
|
-
// }
|
|
442
|
-
// }
|
|
443
|
-
// else
|
|
444
|
-
// {
|
|
445
|
-
// httpAppResponse.error = webResponse.StatusDescription;
|
|
446
|
-
// }
|
|
447
|
-
|
|
448
|
-
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
449
|
-
// }
|
|
450
|
-
// catch (WebException e)
|
|
451
|
-
// {
|
|
452
|
-
// var httpAppResponse = new HttpAppResponse();
|
|
453
|
-
|
|
454
|
-
// httpAppResponse.statusCode = -1;
|
|
455
|
-
|
|
456
|
-
// using (var stream = new StreamReader(e.Response.GetResponseStream()))
|
|
457
|
-
// {
|
|
458
|
-
// httpAppResponse.error = stream.ReadToEnd();
|
|
459
|
-
// }
|
|
460
|
-
|
|
461
|
-
// if (string.IsNullOrEmpty(httpAppResponse.error)) httpAppResponse.error = e.Message;
|
|
462
|
-
|
|
463
|
-
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
464
|
-
// }
|
|
465
|
-
// catch (Exception e)
|
|
466
|
-
// {
|
|
467
|
-
// var httpAppResponse = new HttpAppResponse();
|
|
468
|
-
|
|
469
|
-
// httpAppResponse.statusCode = -1;
|
|
470
|
-
// httpAppResponse.error = e.Message;
|
|
471
|
-
|
|
472
|
-
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
473
|
-
// }
|
|
474
|
-
//}
|
|
475
|
-
|
|
476
|
-
public NetworkingPeerHttpWebRequest()
|
|
477
|
-
{
|
|
478
|
-
//HTTPManager.KeepAliveDefaultValue = true;
|
|
479
|
-
|
|
480
|
-
this.client = new HttpClient();
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
}
|
|
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
|
+
|
|
153
|
+
var content = Encoding.UTF8.GetBytes(Serializer.Serialize(param.toData()));
|
|
154
|
+
|
|
155
|
+
requestMessage.Content = new ByteArrayContent(content);
|
|
156
|
+
|
|
157
|
+
requestMessage.Headers.Add(Commands.CONTENT_TYPE, Commands.APPLICATION_JSON);
|
|
158
|
+
}
|
|
159
|
+
else if (postType == PostType.MsgPack)
|
|
160
|
+
{
|
|
161
|
+
|
|
162
|
+
var content = MsgPackSerializer.Serialize(param.toData());
|
|
163
|
+
|
|
164
|
+
requestMessage.Content = new ByteArrayContent(content);
|
|
165
|
+
|
|
166
|
+
requestMessage.Headers.Add(Commands.CONTENT_TYPE, Commands.APPLICATION_MSGPACK);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (!string.IsNullOrEmpty(authToken)) requestMessage.Headers.Add(Commands.RequestAuthTokenCmd, authToken);
|
|
170
|
+
if (!string.IsNullOrEmpty(secretKey)) requestMessage.Headers.Add(Commands.RequestSecretCmd, secretKey);
|
|
171
|
+
|
|
172
|
+
try
|
|
173
|
+
{
|
|
174
|
+
var webResponse = await this.client.SendAsync(requestMessage);
|
|
175
|
+
|
|
176
|
+
var httpAppResponse = new HttpAppResponse();
|
|
177
|
+
httpAppResponse.statusCode = (int)webResponse.StatusCode;
|
|
178
|
+
|
|
179
|
+
if (webResponse.StatusCode == HttpStatusCode.OK)
|
|
180
|
+
{
|
|
181
|
+
httpAppResponse.data = await webResponse.Content.ReadAsByteArrayAsync();
|
|
182
|
+
httpAppResponse.text = await webResponse.Content.ReadAsStringAsync();
|
|
183
|
+
}
|
|
184
|
+
else
|
|
185
|
+
{
|
|
186
|
+
httpAppResponse.error = webResponse.ReasonPhrase;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
onHttpAppResponse?.Invoke(httpAppResponse);
|
|
190
|
+
}
|
|
191
|
+
catch (Exception e)
|
|
192
|
+
{
|
|
193
|
+
var httpAppResponse = new HttpAppResponse();
|
|
194
|
+
|
|
195
|
+
httpAppResponse.statusCode = -1;
|
|
196
|
+
httpAppResponse.error = e.Message;
|
|
197
|
+
|
|
198
|
+
onHttpAppResponse?.Invoke(httpAppResponse);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
//private async void postRequestViaHttpWeb(string subUri, GNHashtable param, PostType postType, Action<HttpAppResponse> onHttpAppResponse, float timeout, string authToken, string secretKey, GNHashtable customTags)
|
|
204
|
+
//{
|
|
205
|
+
// try
|
|
206
|
+
// {
|
|
207
|
+
// var httpRequest = (HttpWebRequest)WebRequest.Create(this.httpUrl + "/" + subUri);
|
|
208
|
+
// httpRequest.UserAgent = this.userAgent;
|
|
209
|
+
// httpRequest.SendChunked = false;
|
|
210
|
+
// // Prevents hitting a proxy if no proxy is available. TODO: Add support for proxy's.
|
|
211
|
+
// httpRequest.Proxy = null;
|
|
212
|
+
|
|
213
|
+
// httpRequest.Method = NetworkingPeerHttpWebRequest.POST;
|
|
214
|
+
// httpRequest.KeepAlive = false;
|
|
215
|
+
// httpRequest.Timeout = (int)timeout;
|
|
216
|
+
// httpRequest.ReadWriteTimeout = (int)timeout;
|
|
217
|
+
|
|
218
|
+
// if (param == null) param = new GNHashtable();
|
|
219
|
+
|
|
220
|
+
// if (customTags != null) param.add(GNParameterCode.CustomTags, customTags);
|
|
221
|
+
|
|
222
|
+
// if (postType == PostType.Json)
|
|
223
|
+
// {
|
|
224
|
+
// httpRequest.Headers.Add(Commands.CONTENT_TYPE, Commands.APPLICATION_JSON);
|
|
225
|
+
|
|
226
|
+
// var content = Encoding.UTF8.GetBytes(Serializer.Serialize(param.toData()));
|
|
227
|
+
|
|
228
|
+
// using (var stream = httpRequest.GetRequestStream())
|
|
229
|
+
// {
|
|
230
|
+
// stream.Write(content, 0, content.Length);
|
|
231
|
+
// }
|
|
232
|
+
// }
|
|
233
|
+
// else if (postType == PostType.MsgPack)
|
|
234
|
+
// {
|
|
235
|
+
// httpRequest.Headers.Add(Commands.CONTENT_TYPE, Commands.APPLICATION_MSGPACK);
|
|
236
|
+
|
|
237
|
+
// var content = MsgPackSerializer.Serialize(param.toData());
|
|
238
|
+
|
|
239
|
+
// using (var stream = httpRequest.GetRequestStream())
|
|
240
|
+
// {
|
|
241
|
+
// stream.Write(content, 0, content.Length);
|
|
242
|
+
// }
|
|
243
|
+
// }
|
|
244
|
+
|
|
245
|
+
// if (!string.IsNullOrEmpty(authToken)) httpRequest.Headers.Add(Commands.RequestAuthTokenCmd, authToken);
|
|
246
|
+
// if (!string.IsNullOrEmpty(secretKey)) httpRequest.Headers.Add(Commands.RequestSecretCmd, secretKey);
|
|
247
|
+
|
|
248
|
+
// var response = await httpRequest.GetResponseAsync();
|
|
249
|
+
|
|
250
|
+
// var webResponse = (HttpWebResponse)response;
|
|
251
|
+
|
|
252
|
+
// var httpAppResponse = new HttpAppResponse();
|
|
253
|
+
// httpAppResponse.statusCode = (int)webResponse.StatusCode;
|
|
254
|
+
|
|
255
|
+
// if (webResponse.StatusCode == HttpStatusCode.OK)
|
|
256
|
+
// {
|
|
257
|
+
// using (var responseStream = webResponse.GetResponseStream())
|
|
258
|
+
// {
|
|
259
|
+
// using (var memoryStream = new MemoryStream())
|
|
260
|
+
// {
|
|
261
|
+
// responseStream.CopyTo(memoryStream);
|
|
262
|
+
|
|
263
|
+
// httpAppResponse.data = memoryStream.ToArray();
|
|
264
|
+
// }
|
|
265
|
+
|
|
266
|
+
// using (var stream = new StreamReader(responseStream))
|
|
267
|
+
// {
|
|
268
|
+
// httpAppResponse.text = stream.ReadToEnd();
|
|
269
|
+
// }
|
|
270
|
+
// }
|
|
271
|
+
// }
|
|
272
|
+
// else
|
|
273
|
+
// {
|
|
274
|
+
// httpAppResponse.error = webResponse.StatusDescription;
|
|
275
|
+
// }
|
|
276
|
+
|
|
277
|
+
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
278
|
+
// }
|
|
279
|
+
// catch (WebException e)
|
|
280
|
+
// {
|
|
281
|
+
// var httpAppResponse = new HttpAppResponse();
|
|
282
|
+
|
|
283
|
+
// httpAppResponse.statusCode = -1;
|
|
284
|
+
|
|
285
|
+
// using (var stream = new StreamReader(e.Response.GetResponseStream()))
|
|
286
|
+
// {
|
|
287
|
+
// httpAppResponse.error = stream.ReadToEnd();
|
|
288
|
+
// }
|
|
289
|
+
|
|
290
|
+
// if (string.IsNullOrEmpty(httpAppResponse.error)) httpAppResponse.error = e.Message;
|
|
291
|
+
|
|
292
|
+
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
293
|
+
// }
|
|
294
|
+
// catch (Exception e)
|
|
295
|
+
// {
|
|
296
|
+
// var httpAppResponse = new HttpAppResponse();
|
|
297
|
+
|
|
298
|
+
// httpAppResponse.statusCode = -1;
|
|
299
|
+
// httpAppResponse.error = e.Message;
|
|
300
|
+
|
|
301
|
+
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
302
|
+
// }
|
|
303
|
+
//}
|
|
304
|
+
|
|
305
|
+
public override void postRequestUpload(string subUri, byte[] content, string mimetype, Action<HttpAppResponse> onHttpAppResponse, float timeout)
|
|
306
|
+
{
|
|
307
|
+
this.postRequestUploadViaHttpWeb(subUri, content, mimetype, onHttpAppResponse, timeout);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
private async void postRequestUploadViaHttpWeb(string subUri, byte[] content, string mimetype, Action<HttpAppResponse> onHttpAppResponse, float timeout)
|
|
311
|
+
{
|
|
312
|
+
//try
|
|
313
|
+
//{
|
|
314
|
+
// var httpRequest = (HttpWebRequest)WebRequest.Create(this.httpUrl + "/" + subUri);
|
|
315
|
+
// httpRequest.UserAgent = this.userAgent;
|
|
316
|
+
// httpRequest.SendChunked = false;
|
|
317
|
+
// // Prevents hitting a proxy if no proxy is available. TODO: Add support for proxy's.
|
|
318
|
+
// httpRequest.Proxy = null;
|
|
319
|
+
|
|
320
|
+
// httpRequest.Method = NetworkingPeerHttpWebRequest.POST;
|
|
321
|
+
// httpRequest.KeepAlive = false;
|
|
322
|
+
// httpRequest.Timeout = (int)timeout;
|
|
323
|
+
// httpRequest.ReadWriteTimeout = (int)timeout;
|
|
324
|
+
|
|
325
|
+
// var authToken = GNNetwork.getAuthenticateStatus().getAuthToken();
|
|
326
|
+
|
|
327
|
+
// if (!string.IsNullOrEmpty(authToken)) httpRequest.Headers.Add(Commands.RequestAuthTokenCmd, authToken);
|
|
328
|
+
|
|
329
|
+
// var headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n" + "Content-Type: application/octet-stream\r\n\r\n";
|
|
330
|
+
|
|
331
|
+
// using (var stream = httpRequest.GetRequestStream())
|
|
332
|
+
// {
|
|
333
|
+
// stream.Write(content, 0, content.Length);
|
|
334
|
+
// }
|
|
335
|
+
|
|
336
|
+
// var response = await httpRequest.GetResponseAsync();
|
|
337
|
+
|
|
338
|
+
// var webResponse = (HttpWebResponse)response;
|
|
339
|
+
|
|
340
|
+
// var httpAppResponse = new HttpAppResponse();
|
|
341
|
+
// httpAppResponse.statusCode = (int)webResponse.StatusCode;
|
|
342
|
+
|
|
343
|
+
// if (webResponse.StatusCode == HttpStatusCode.OK)
|
|
344
|
+
// {
|
|
345
|
+
// using (var responseStream = webResponse.GetResponseStream())
|
|
346
|
+
// {
|
|
347
|
+
// using (var memoryStream = new MemoryStream())
|
|
348
|
+
// {
|
|
349
|
+
// responseStream.CopyTo(memoryStream);
|
|
350
|
+
|
|
351
|
+
// httpAppResponse.data = memoryStream.ToArray();
|
|
352
|
+
// }
|
|
353
|
+
|
|
354
|
+
// using (var stream = new StreamReader(responseStream))
|
|
355
|
+
// {
|
|
356
|
+
// httpAppResponse.text = stream.ReadToEnd();
|
|
357
|
+
// }
|
|
358
|
+
// }
|
|
359
|
+
// }
|
|
360
|
+
// else
|
|
361
|
+
// {
|
|
362
|
+
// httpAppResponse.error = webResponse.StatusDescription;
|
|
363
|
+
// }
|
|
364
|
+
|
|
365
|
+
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
366
|
+
//}
|
|
367
|
+
//catch (WebException e)
|
|
368
|
+
//{
|
|
369
|
+
// var httpAppResponse = new HttpAppResponse();
|
|
370
|
+
|
|
371
|
+
// httpAppResponse.statusCode = -1;
|
|
372
|
+
|
|
373
|
+
// using (var stream = new StreamReader(e.Response.GetResponseStream()))
|
|
374
|
+
// {
|
|
375
|
+
// httpAppResponse.error = stream.ReadToEnd();
|
|
376
|
+
// }
|
|
377
|
+
|
|
378
|
+
// if (string.IsNullOrEmpty(httpAppResponse.error)) httpAppResponse.error = e.Message;
|
|
379
|
+
|
|
380
|
+
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
381
|
+
//}
|
|
382
|
+
//catch (Exception e)
|
|
383
|
+
//{
|
|
384
|
+
// var httpAppResponse = new HttpAppResponse();
|
|
385
|
+
|
|
386
|
+
// httpAppResponse.statusCode = -1;
|
|
387
|
+
// httpAppResponse.error = e.Message;
|
|
388
|
+
|
|
389
|
+
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
390
|
+
//}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
//private async void postRequestUploadViaHttpWeb(string subUri, byte[] content, string mimetype, Action<HttpAppResponse> onHttpAppResponse, float timeout)
|
|
394
|
+
//{
|
|
395
|
+
// try
|
|
396
|
+
// {
|
|
397
|
+
// var httpRequest = (HttpWebRequest)WebRequest.Create(this.httpUrl + "/" + subUri);
|
|
398
|
+
// httpRequest.UserAgent = this.userAgent;
|
|
399
|
+
// httpRequest.SendChunked = false;
|
|
400
|
+
// // Prevents hitting a proxy if no proxy is available. TODO: Add support for proxy's.
|
|
401
|
+
// httpRequest.Proxy = null;
|
|
402
|
+
|
|
403
|
+
// httpRequest.Method = NetworkingPeerHttpWebRequest.POST;
|
|
404
|
+
// httpRequest.KeepAlive = false;
|
|
405
|
+
// httpRequest.Timeout = (int)timeout;
|
|
406
|
+
// httpRequest.ReadWriteTimeout = (int)timeout;
|
|
407
|
+
|
|
408
|
+
// var authToken = GNNetwork.getAuthenticateStatus().getAuthToken();
|
|
409
|
+
|
|
410
|
+
// if (!string.IsNullOrEmpty(authToken)) httpRequest.Headers.Add(Commands.RequestAuthTokenCmd, authToken);
|
|
411
|
+
|
|
412
|
+
// var headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n" + "Content-Type: application/octet-stream\r\n\r\n";
|
|
413
|
+
|
|
414
|
+
// using (var stream = httpRequest.GetRequestStream())
|
|
415
|
+
// {
|
|
416
|
+
// stream.Write(content, 0, content.Length);
|
|
417
|
+
// }
|
|
418
|
+
|
|
419
|
+
// var response = await httpRequest.GetResponseAsync();
|
|
420
|
+
|
|
421
|
+
// var webResponse = (HttpWebResponse)response;
|
|
422
|
+
|
|
423
|
+
// var httpAppResponse = new HttpAppResponse();
|
|
424
|
+
// httpAppResponse.statusCode = (int)webResponse.StatusCode;
|
|
425
|
+
|
|
426
|
+
// if (webResponse.StatusCode == HttpStatusCode.OK)
|
|
427
|
+
// {
|
|
428
|
+
// using (var responseStream = webResponse.GetResponseStream())
|
|
429
|
+
// {
|
|
430
|
+
// using (var memoryStream = new MemoryStream())
|
|
431
|
+
// {
|
|
432
|
+
// responseStream.CopyTo(memoryStream);
|
|
433
|
+
|
|
434
|
+
// httpAppResponse.data = memoryStream.ToArray();
|
|
435
|
+
// }
|
|
436
|
+
|
|
437
|
+
// using (var stream = new StreamReader(responseStream))
|
|
438
|
+
// {
|
|
439
|
+
// httpAppResponse.text = stream.ReadToEnd();
|
|
440
|
+
// }
|
|
441
|
+
// }
|
|
442
|
+
// }
|
|
443
|
+
// else
|
|
444
|
+
// {
|
|
445
|
+
// httpAppResponse.error = webResponse.StatusDescription;
|
|
446
|
+
// }
|
|
447
|
+
|
|
448
|
+
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
449
|
+
// }
|
|
450
|
+
// catch (WebException e)
|
|
451
|
+
// {
|
|
452
|
+
// var httpAppResponse = new HttpAppResponse();
|
|
453
|
+
|
|
454
|
+
// httpAppResponse.statusCode = -1;
|
|
455
|
+
|
|
456
|
+
// using (var stream = new StreamReader(e.Response.GetResponseStream()))
|
|
457
|
+
// {
|
|
458
|
+
// httpAppResponse.error = stream.ReadToEnd();
|
|
459
|
+
// }
|
|
460
|
+
|
|
461
|
+
// if (string.IsNullOrEmpty(httpAppResponse.error)) httpAppResponse.error = e.Message;
|
|
462
|
+
|
|
463
|
+
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
464
|
+
// }
|
|
465
|
+
// catch (Exception e)
|
|
466
|
+
// {
|
|
467
|
+
// var httpAppResponse = new HttpAppResponse();
|
|
468
|
+
|
|
469
|
+
// httpAppResponse.statusCode = -1;
|
|
470
|
+
// httpAppResponse.error = e.Message;
|
|
471
|
+
|
|
472
|
+
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
473
|
+
// }
|
|
474
|
+
//}
|
|
475
|
+
|
|
476
|
+
public NetworkingPeerHttpWebRequest()
|
|
477
|
+
{
|
|
478
|
+
//HTTPManager.KeepAliveDefaultValue = true;
|
|
479
|
+
|
|
480
|
+
this.client = new HttpClient();
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
}
|