|
@@ -51,14 +51,7 @@ namespace BO.Connector
|
|
|
public void Open(string userName, string userPassword, string magicKey)
|
|
public void Open(string userName, string userPassword, string magicKey)
|
|
|
{
|
|
{
|
|
|
Log(LogSeverityEnum.Trace, $"Opening Connector '{ApiName}' open with magicKey='{magicKey}'");
|
|
Log(LogSeverityEnum.Trace, $"Opening Connector '{ApiName}' open with magicKey='{magicKey}'");
|
|
|
- _client = new HttpClient();
|
|
|
|
|
- _client.BaseAddress = new Uri(_uriApiBase, ApiName);
|
|
|
|
|
- _client.Timeout = _timeout;
|
|
|
|
|
- _client.DefaultRequestHeaders.Accept.Clear();
|
|
|
|
|
- _client.DefaultRequestHeaders.Add("User-Agent", "BO.Connector." + ApiName);
|
|
|
|
|
- // Add an Accept header for JSON format.
|
|
|
|
|
- _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
|
|
|
|
-
|
|
|
|
|
|
|
+ _client = CreateClient();
|
|
|
InitTicket(magicKey);
|
|
InitTicket(magicKey);
|
|
|
Login(userName, userPassword);
|
|
Login(userName, userPassword);
|
|
|
Log(LogSeverityEnum.Debug, $"Connector '{ApiName}' open for user '{userName}' with timeout setting {_timeout}.");
|
|
Log(LogSeverityEnum.Debug, $"Connector '{ApiName}' open for user '{userName}' with timeout setting {_timeout}.");
|
|
@@ -174,7 +167,7 @@ namespace BO.Connector
|
|
|
foreach (var key in headerAttributes.Keys)
|
|
foreach (var key in headerAttributes.Keys)
|
|
|
req.Headers.Add(key,headerAttributes[key]);
|
|
req.Headers.Add(key,headerAttributes[key]);
|
|
|
req.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
|
req.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
|
|
- resp = await _client.PostAsync(relativeUrlApiCall, req);
|
|
|
|
|
|
|
+ resp = await CreateClient().PostAsync(relativeUrlApiCall, req);
|
|
|
break;
|
|
break;
|
|
|
case RestCallTypeEnum.Put:
|
|
case RestCallTypeEnum.Put:
|
|
|
req = new StringContent(_binder.SaveToString(data));
|
|
req = new StringContent(_binder.SaveToString(data));
|
|
@@ -228,6 +221,18 @@ namespace BO.Connector
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ private HttpClient CreateClient()
|
|
|
|
|
+ {
|
|
|
|
|
+ var client = new HttpClient();
|
|
|
|
|
+ client.BaseAddress = new Uri(_uriApiBase, ApiName);
|
|
|
|
|
+ client.Timeout = _timeout;
|
|
|
|
|
+ client.DefaultRequestHeaders.Accept.Clear();
|
|
|
|
|
+ client.DefaultRequestHeaders.Add("User-Agent", "BO.Connector." + ApiName);
|
|
|
|
|
+ // Add an Accept header for JSON format.
|
|
|
|
|
+ client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
|
|
|
|
+ return client;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
}
|
|
}
|