This commit is contained in:
Oliver Hauff 2022-01-22 18:28:01 +01:00
parent f38b516d25
commit 578fcee611
70 changed files with 6828 additions and 9625 deletions

View file

@ -733,18 +733,18 @@ namespace TINK.Repository
}
/// <summary> http- post request.</summary>
/// <param name="p_strCommand">Command to send.</param>
/// <param name="p_oDisplayCommand">Command to display/ log used for error handling.</param>
/// <param name="command">Command to send.</param>
/// <param name="displayCommand">Command to display/ log used for error handling.</param>
/// <param name="uRL">Address of server to communicate with.</param>
/// <returns>Response as text.</returns>
/// <changelog> An unused member PostAsyncHttpClient using HttpClient for posting was removed 2020-04-02.</changelog>
private static async Task<string> PostAsync(
string uRL,
string p_strCommand,
string command,
string userAgent = null,
Func<string> p_oDisplayCommand = null)
Func<string> displayCommand = null)
{
if (string.IsNullOrEmpty(p_strCommand))
if (string.IsNullOrEmpty(command))
{
Log.ForContext<CopriCallsHttps>().Fatal("Can not post command. Command must not be null or empty.");
@ -759,7 +759,7 @@ namespace TINK.Repository
}
// Get display version of command to used for display/ logging (password should never be included in output)
Func<string> displayCommandFunc = p_oDisplayCommand ?? delegate () { return p_strCommand; };
Func<string> displayCommandFunc = displayCommand ?? delegate () { return command; };
try
{
@ -769,7 +769,6 @@ namespace TINK.Repository
// Returns a http request.
var request = WebRequest.CreateHttp(l_strHost);
request.Timeout = 5000; // Default value for HttpWebRequest is 100 secs. According to doc this has no impact on async call but when debugging it has.
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.UserAgent = userAgent;
@ -778,38 +777,38 @@ namespace TINK.Repository
// If not KeepAlive is set to true Stream.Write leads arbitrarily to an object disposed exception.
request.KeepAlive = true;
byte[] l_oPostData = Encoding.UTF8.GetBytes(p_strCommand);
byte[] postData = Encoding.UTF8.GetBytes(command);
request.ContentLength = l_oPostData.Length;
request.ContentLength = postData.Length;
// Get the request stream.
using (Stream l_oDataStream = await request.GetRequestStreamAsync())
using (Stream dataStream = await request.GetRequestStreamAsync())
{
// Write the data to the request stream.
await l_oDataStream.WriteAsync(l_oPostData, 0, l_oPostData.Length);
await dataStream.WriteAsync(postData, 0, postData.Length);
}
// Get the response.
var l_oResponse = await request.GetResponseAsync() as HttpWebResponse;
var webResponse = await request.GetResponseAsync() as HttpWebResponse;
if (l_oResponse == null)
if (webResponse == null)
{
throw new System.Exception(string.Format("Reserve request failed. Response form from server was not of expected type."));
}
if (l_oResponse.StatusCode != HttpStatusCode.OK)
if (webResponse.StatusCode != HttpStatusCode.OK)
{
throw new CommunicationException(string.Format(
"Posting request {0} failed. Expected status code is {1} but was {2}.",
displayCommandFunc(),
HttpStatusCode.OK,
l_oResponse.StatusCode));
webResponse.StatusCode));
}
string response = string.Empty;
// Get the request stream.
using (Stream l_oDataStream = l_oResponse.GetResponseStream())
using (Stream l_oDataStream = webResponse.GetResponseStream())
using (StreamReader l_oReader = new StreamReader(l_oDataStream))
{
// Read the content.
@ -819,7 +818,7 @@ namespace TINK.Repository
Console.WriteLine(response);
// Clean up the streams.
l_oResponse.Close();
webResponse.Close();
}
Log.ForContext<CopriCallsHttps>().Verbose("Post command {DisplayCommand} to host {URL} received {ResponseText:j}.", displayCommandFunc(), uRL, response);

View file

@ -1,7 +1,5 @@

using System.Runtime.Serialization;
namespace TINK.Repository.Response
{
/// <summary>

View file

@ -25,6 +25,26 @@ namespace TINK.Repository.Response
[DataMember]
public MapSpan init_map { get; private set; }
/// <summary> Url of page holding agb info. </summary>
[DataMember]
public string agb_html { get; private set; }
/// <summary> Url of page holding instructions how to rent bikes. </summary>
[DataMember]
public string bike_info_html { get; private set; }
/// <summary> Url of page holding privacy info. </summary>
[DataMember]
public string privacy_html { get; private set; }
/// <summary> Url of page holding impress info. </summary>
[DataMember]
public string impress_html { get; private set; }
/// <summary> Url of page holding tariff info. </summary>
[DataMember]
public string tariff_info_html { get; private set; }
/// <summary> Textual description of response. </summary>
public new string ToString()
{