@@ -282,16 +282,16 @@ public static string POSTMethod_Extended(ref ExtendedResult extResult, string ur
282
282
{
283
283
request . Headers . Add ( Header . Name , Header . Value ) ;
284
284
}
285
-
286
- // Set default Content-Type
287
- if ( string . IsNullOrEmpty ( request . ContentType ) )
288
- {
289
- request . ContentType = CONTENTTYPE ;
290
- }
291
285
}
292
286
}
293
287
}
294
-
288
+
289
+ // Set default Content-Type
290
+ if ( string . IsNullOrEmpty ( request . ContentType ) )
291
+ {
292
+ request . ContentType = CONTENTTYPE ;
293
+ }
294
+
295
295
if ( request . ContentType . ToLower ( ) == CONTENTTYPE_URLENCODED . ToLower ( ) )
296
296
{
297
297
byte [ ] byteArray = System . Text . Encoding . UTF8 . GetBytes ( ( ! String . IsNullOrEmpty ( JsonBody ) ) ? JsonBody : "" ) ;
@@ -392,7 +392,6 @@ public static string POSTMethod_Extended(ref ExtendedResult extResult, string ur
392
392
return ContentResult ;
393
393
}
394
394
395
-
396
395
/// <summary>
397
396
/// POST to Resful API sending Json body.
398
397
/// </summary>
@@ -848,16 +847,17 @@ public static string GETMethod_Extended(ref ExtendedResult extResult, string url
848
847
request . Headers . Add ( Header . Name , Header . Value ) ;
849
848
}
850
849
851
- // Set default Content-Type
852
- if ( string . IsNullOrEmpty ( request . ContentType ) )
853
- {
854
- request . ContentType = CONTENTTYPE ;
855
- }
856
850
}
857
851
858
852
}
859
853
}
860
854
855
+ // Set default Content-Type
856
+ if ( string . IsNullOrEmpty ( request . ContentType ) )
857
+ {
858
+ request . ContentType = CONTENTTYPE ;
859
+ }
860
+
861
861
if ( request . ContentType . ToLower ( ) == CONTENTTYPE_URLENCODED . ToLower ( ) )
862
862
{
863
863
byte [ ] byteArray = System . Text . Encoding . UTF8 . GetBytes ( ( ! String . IsNullOrEmpty ( JsonBody ) ) ? JsonBody : "" ) ;
@@ -999,22 +999,41 @@ public static string WebMethod(string httpMethod, string url, string JsonBody =
999
999
request . Headers . Add ( Header . Name , Header . Value ) ;
1000
1000
}
1001
1001
1002
- // Set default Content-Type
1003
- if ( string . IsNullOrEmpty ( request . ContentType ) )
1004
- {
1005
- request . ContentType = CONTENTTYPE ;
1006
- }
1007
1002
}
1008
1003
1009
1004
}
1010
1005
}
1011
1006
1012
- using ( var streamWriter = new StreamWriter ( request . GetRequestStream ( ) ) )
1007
+ // Set default Content-Type
1008
+ if ( string . IsNullOrEmpty ( request . ContentType ) )
1013
1009
{
1014
- if ( ! String . IsNullOrEmpty ( JsonBody ) )
1015
- streamWriter . Write ( JsonBody ) ;
1010
+ request . ContentType = CONTENTTYPE ;
1011
+ }
1016
1012
1017
- streamWriter . Flush ( ) ;
1013
+ if ( request . ContentType . ToLower ( ) == CONTENTTYPE_URLENCODED . ToLower ( ) )
1014
+ {
1015
+ byte [ ] byteArray = System . Text . Encoding . UTF8 . GetBytes ( ( ! String . IsNullOrEmpty ( JsonBody ) ) ? JsonBody : "" ) ;
1016
+ // Set the ContentLength property of the WebRequest.
1017
+ request . ContentLength = byteArray . Length ;
1018
+
1019
+ using ( var streamWriter = request . GetRequestStream ( ) )
1020
+ {
1021
+ streamWriter . Write ( byteArray , 0 , byteArray . Length ) ;
1022
+ // Close the Stream object.
1023
+ streamWriter . Close ( ) ;
1024
+ // Get the response.
1025
+
1026
+ streamWriter . Flush ( ) ;
1027
+ }
1028
+ }
1029
+ else if ( ! String . IsNullOrEmpty ( JsonBody )
1030
+ && ! httpMethod . ToUpper ( ) . Contains ( "GET" ) )
1031
+ {
1032
+ using ( var streamWriter = new StreamWriter ( request . GetRequestStream ( ) ) )
1033
+ {
1034
+ streamWriter . Write ( JsonBody ) ;
1035
+ streamWriter . Flush ( ) ;
1036
+ }
1018
1037
}
1019
1038
1020
1039
var httpResponse = ( HttpWebResponse ) request . GetResponse ( ) ;
@@ -1090,17 +1109,16 @@ public static string WebMethod_Extended(ref ExtendedResult extResult, string htt
1090
1109
{
1091
1110
request . Headers . Add ( Header . Name , Header . Value ) ;
1092
1111
}
1093
-
1094
- // Set default Content-Type
1095
- if ( string . IsNullOrEmpty ( request . ContentType ) )
1096
- {
1097
- request . ContentType = CONTENTTYPE ;
1098
- }
1099
1112
}
1100
-
1101
1113
}
1102
1114
}
1103
1115
1116
+ // Set default Content-Type
1117
+ if ( string . IsNullOrEmpty ( request . ContentType ) )
1118
+ {
1119
+ request . ContentType = CONTENTTYPE ;
1120
+ }
1121
+
1104
1122
if ( request . ContentType . ToLower ( ) == CONTENTTYPE_URLENCODED . ToLower ( ) )
1105
1123
{
1106
1124
byte [ ] byteArray = System . Text . Encoding . UTF8 . GetBytes ( ( ! String . IsNullOrEmpty ( JsonBody ) ) ? JsonBody : "" ) ;
0 commit comments