@@ -43,23 +43,23 @@ namespace ContractTools.WebApp.Base
43
43
{
44
44
public static class NetHelper
45
45
{
46
- public static int LoginActionId = ConfigUtils . GetSetting ( "UnitTest.LoginActionId" , 1004 ) ;
46
+ public static String LoginActionId = ConfigUtils . GetSetting ( "UnitTest.LoginActionId" , "1001,1003, 1004" ) ;
47
47
private static string SignKey = ConfigUtils . GetSetting ( "Product.SignKey" ) ;
48
48
public static string ClientDesDeKey = ConfigUtils . GetSetting ( "Product.ClientDesDeKey" , "j6=9=1ac" ) ;
49
49
private static bool IsGet = true ;
50
50
51
- public static MessageStructure Create ( string serverUrl , string requestParams , out MessageHead header , bool isSocket , int actionId , string pid , CookieContainer cookies )
51
+ public static Stream Create ( string serverUrl , string requestParams , bool isSocket , int actionId , string pid , bool includeParam , CookieContainer cookies )
52
52
{
53
- header = null ;
54
53
MessageStructure msgReader = null ;
55
54
if ( isSocket )
56
55
{
57
- msgReader = DoRequest ( serverUrl , requestParams , actionId , pid ) ;
56
+ return DoRequest ( serverUrl , requestParams , actionId , pid , includeParam ) ;
58
57
}
59
58
else
60
59
{
61
60
Encoding encode = Encoding . GetEncoding ( "utf-8" ) ;
62
- string postData = "d=" + GetSign ( requestParams ) ;
61
+ string postData = GetSign ( requestParams , includeParam ) ;
62
+ if ( includeParam ) postData = "d=" + postData ;
63
63
HttpWebRequest serverRequest ;
64
64
if ( IsGet )
65
65
{
@@ -81,14 +81,9 @@ public static MessageStructure Create(string serverUrl, string requestParams, ou
81
81
//
82
82
HttpWebResponse serverResponse = ( HttpWebResponse ) serverRequest . GetResponse ( ) ;
83
83
cookies . Add ( serverResponse . Cookies ) ;
84
- Stream responseStream = serverResponse . GetResponseStream ( ) ;
85
- msgReader = MessageStructure . Create ( responseStream , Encoding . UTF8 ) ;
84
+ return serverResponse . GetResponseStream ( ) ;
86
85
}
87
- if ( msgReader != null )
88
- {
89
- header = msgReader . ReadHeadGzip ( ) ;
90
- }
91
- return msgReader ;
86
+
92
87
}
93
88
94
89
public static bool GetFieldValue ( MessageStructure ms , FieldType fieldType , ref string val )
@@ -158,30 +153,32 @@ public static bool GetFieldValue(MessageStructure ms, FieldType fieldType, ref s
158
153
return result ;
159
154
}
160
155
161
- public static string GetSign ( string requestParams )
156
+ public static string GetSign ( string requestParams , bool includeParam )
162
157
{
163
158
string sign = "" ;
164
159
if ( ! string . IsNullOrEmpty ( SignKey ) )
165
160
{
166
161
sign = FormsAuthentication . HashPasswordForStoringInConfigFile ( requestParams + SignKey , "MD5" ) . ToLower ( ) ;
167
162
}
168
- return Uri . EscapeDataString ( string . Format ( "{0}&sign={1}" , requestParams , sign ) ) ;
163
+ if ( includeParam )
164
+ return Uri . EscapeDataString ( string . Format ( "{0}&sign={1}" , requestParams , sign ) ) ;
165
+ return string . Format ( "{0}&sign={1}" , requestParams , sign ) ;
169
166
}
170
167
171
- private static MessageStructure DoRequest ( string server , string param , int actionId , string pid )
168
+ private static Stream DoRequest ( string server , string param , int actionId , string pid , bool includeParam )
172
169
{
173
170
string [ ] serverArray = server . Split ( ':' ) ;
174
- return DoRequest ( serverArray [ 0 ] , Convert . ToInt32 ( serverArray [ 1 ] ) , GetSign ( param ) , actionId , pid ) ;
171
+ return DoRequest ( serverArray [ 0 ] , Convert . ToInt32 ( serverArray [ 1 ] ) , GetSign ( param , includeParam ) , actionId , pid ) ;
175
172
}
176
173
177
- private static MessageStructure DoRequest ( string host , int port , string param , int actionId , string pid )
174
+ private static Stream DoRequest ( string host , int port , string param , int actionId , string pid )
178
175
{
179
176
var remoteEndPoint = new IPEndPoint ( Dns . GetHostAddresses ( host ) [ 0 ] , port ) ;
180
177
return DoRequest ( remoteEndPoint , param , 1024 , actionId , pid ) ;
181
178
}
182
179
183
180
private static ConcurrentDictionary < string , MyConnect > _clientSockets = new ConcurrentDictionary < string , MyConnect > ( ) ;
184
- private static MessageStructure DoRequest ( IPEndPoint remoteEndPoint , string param , int bufferSize , int actionId , string pid )
181
+ private static Stream DoRequest ( IPEndPoint remoteEndPoint , string param , int bufferSize , int actionId , string pid )
185
182
{
186
183
byte [ ] data = Encoding . UTF8 . GetBytes ( "?d=" + param ) ;
187
184
MyConnect myConnect = null ;
@@ -227,7 +224,7 @@ internal class MyConnect
227
224
private int _actionId ;
228
225
private ConcurrentQueue < MyPack > actionPools = new ConcurrentQueue < MyPack > ( ) ;
229
226
private ConcurrentQueue < MyPack > pushPools = new ConcurrentQueue < MyPack > ( ) ;
230
- private MessageStructure ms ;
227
+ private Stream ms ;
231
228
private Timer checkTimer ;
232
229
private int _isRunning = 0 ;
233
230
@@ -260,7 +257,7 @@ private static void OnCheckPack(object state)
260
257
{
261
258
if ( pack . Head . Action == myConnect . _actionId )
262
259
{
263
- myConnect . ms = new MessageStructure ( pack . Data ) ;
260
+ myConnect . ms = new MemoryStream ( pack . Data ) ;
264
261
myConnect . singal . Set ( ) ;
265
262
}
266
263
else
@@ -298,7 +295,7 @@ private static void OnReceive(object sender, SocketEventArgs e)
298
295
}
299
296
300
297
301
- public MessageStructure GetResult ( )
298
+ public Stream GetResult ( )
302
299
{
303
300
singal . WaitOne ( 10000 ) ;
304
301
return ms ;
0 commit comments