Skip to content

Commit b4503d7

Browse files
author
gdiaz
committed
Fix issue when Header parameter is not sent
1 parent 4b468e0 commit b4503d7

File tree

10 files changed

+51
-33
lines changed

10 files changed

+51
-33
lines changed

.vs/SQL-APIConsumer/v15/.suo

11 KB
Binary file not shown.
Binary file not shown.

API_Consumer/Consumers/APIConsumer.cs

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,16 @@ public static string POSTMethod_Extended(ref ExtendedResult extResult, string ur
282282
{
283283
request.Headers.Add(Header.Name, Header.Value);
284284
}
285-
286-
// Set default Content-Type
287-
if (string.IsNullOrEmpty(request.ContentType))
288-
{
289-
request.ContentType = CONTENTTYPE;
290-
}
291285
}
292286
}
293287
}
294-
288+
289+
// Set default Content-Type
290+
if (string.IsNullOrEmpty(request.ContentType))
291+
{
292+
request.ContentType = CONTENTTYPE;
293+
}
294+
295295
if (request.ContentType.ToLower() == CONTENTTYPE_URLENCODED.ToLower())
296296
{
297297
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
392392
return ContentResult;
393393
}
394394

395-
396395
/// <summary>
397396
/// POST to Resful API sending Json body.
398397
/// </summary>
@@ -848,16 +847,17 @@ public static string GETMethod_Extended(ref ExtendedResult extResult, string url
848847
request.Headers.Add(Header.Name, Header.Value);
849848
}
850849

851-
// Set default Content-Type
852-
if (string.IsNullOrEmpty(request.ContentType))
853-
{
854-
request.ContentType = CONTENTTYPE;
855-
}
856850
}
857851

858852
}
859853
}
860854

855+
// Set default Content-Type
856+
if (string.IsNullOrEmpty(request.ContentType))
857+
{
858+
request.ContentType = CONTENTTYPE;
859+
}
860+
861861
if (request.ContentType.ToLower() == CONTENTTYPE_URLENCODED.ToLower())
862862
{
863863
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 =
999999
request.Headers.Add(Header.Name, Header.Value);
10001000
}
10011001

1002-
// Set default Content-Type
1003-
if (string.IsNullOrEmpty(request.ContentType))
1004-
{
1005-
request.ContentType = CONTENTTYPE;
1006-
}
10071002
}
10081003

10091004
}
10101005
}
10111006

1012-
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
1007+
// Set default Content-Type
1008+
if (string.IsNullOrEmpty(request.ContentType))
10131009
{
1014-
if (!String.IsNullOrEmpty(JsonBody))
1015-
streamWriter.Write(JsonBody);
1010+
request.ContentType = CONTENTTYPE;
1011+
}
10161012

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+
}
10181037
}
10191038

10201039
var httpResponse = (HttpWebResponse)request.GetResponse();
@@ -1090,17 +1109,16 @@ public static string WebMethod_Extended(ref ExtendedResult extResult, string htt
10901109
{
10911110
request.Headers.Add(Header.Name, Header.Value);
10921111
}
1093-
1094-
// Set default Content-Type
1095-
if (string.IsNullOrEmpty(request.ContentType))
1096-
{
1097-
request.ContentType = CONTENTTYPE;
1098-
}
10991112
}
1100-
11011113
}
11021114
}
11031115

1116+
// Set default Content-Type
1117+
if (string.IsNullOrEmpty(request.ContentType))
1118+
{
1119+
request.ContentType = CONTENTTYPE;
1120+
}
1121+
11041122
if (request.ContentType.ToLower() == CONTENTTYPE_URLENCODED.ToLower())
11051123
{
11061124
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes((!String.IsNullOrEmpty(JsonBody)) ? JsonBody : "");

API_Consumer/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
// Build Number
2020
// Revision
2121
//
22-
[assembly: AssemblyVersion("2.3.5.0")]
23-
[assembly: AssemblyFileVersion("2.3.5.0")]
22+
[assembly: AssemblyVersion("2.3.6.1")]
23+
[assembly: AssemblyFileVersion("2.3.6.1")]
512 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
78 Bytes
Binary file not shown.

API_Consumer/obj/Debug/API_CONSUMER.generated.sql

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.
512 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)