wasSharp

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 24  →  ?path2? @ 23
/Web/wasHTTPClient.cs
@@ -6,12 +6,12 @@
 
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using wasSharp.Collections.Utilities;
 
namespace wasSharp.Web
{
@@ -85,11 +85,6 @@
MediaType = mediaType;
}
 
public void Dispose()
{
HTTPClient?.Dispose();
}
 
///////////////////////////////////////////////////////////////////////////
// Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
@@ -219,68 +214,6 @@
// Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
/// <summary>
/// Sends a PUT request to an URL with stream content data.
/// </summary>
/// <param name="URL">the url to send the message to</param>
/// <param name="data">key-value pairs to send</param>
public async Task<byte[]> PUT(string URL, Stream data)
{
try
{
using (var streamContenet = new StreamContent(data))
{
using (var response = await HTTPClient.PutAsync(URL, streamContenet))
{
return response.IsSuccessStatusCode
? await response.Content.ReadAsByteArrayAsync()
: null;
}
}
}
catch (Exception)
{
return null;
}
}
 
///////////////////////////////////////////////////////////////////////////
// Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
/// <summary>
/// Sends a DELETE request to an URL with stream content data.
/// </summary>
/// <param name="URL">the url to send the message to</param>
/// <param name="data">key-value pairs to send</param>
public async Task<byte[]> DELETE(string URL, Stream data)
{
try
{
using (var streamContenet = new StreamContent(data))
{
using (var request = new HttpRequestMessage(HttpMethod.Delete, URL)
{
Content = streamContenet
})
{
using (var response = await HTTPClient.SendAsync(request))
{
return response.IsSuccessStatusCode
? await response.Content.ReadAsByteArrayAsync()
: null;
}
}
}
}
catch (Exception)
{
return null;
}
}
 
///////////////////////////////////////////////////////////////////////////
// Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
/// <summary>
/// Sends a PUT request to an URL with text.
/// </summary>
/// <param name="URL">the url to send the message to</param>
@@ -310,41 +243,6 @@
// Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
/// <summary>
/// Sends a PUT request to an URL with text.
/// </summary>
/// <param name="URL">the url to send the message to</param>
/// <param name="data">key-value pairs to send</param>
public async Task<byte[]> DELETE(string URL, string data)
{
try
{
using (var content =
new StringContent(data, Encoding.UTF8, MediaType))
{
using (var request = new HttpRequestMessage(HttpMethod.Delete, URL)
{
Content = content
})
{
using (var response = await HTTPClient.SendAsync(request))
{
return response.IsSuccessStatusCode
? await response.Content.ReadAsByteArrayAsync()
: null;
}
}
}
}
catch (Exception)
{
return null;
}
}
 
///////////////////////////////////////////////////////////////////////////
// Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
/// <summary>
/// Sends a POST request to an URL with set key-value pairs.
/// </summary>
/// <param name="URL">the url to send the message to</param>
@@ -374,35 +272,6 @@
// Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
/// <summary>
/// Sends a POST request to an URL with set key-value pairs.
/// </summary>
/// <param name="URL">the url to send the message to</param>
/// <param name="message">key-value pairs to send</param>
public async Task<byte[]> POST(string URL, IEnumerable<KeyValuePair<string, string>> message)
{
try
{
using (var content =
new StringContent(KeyValue.Encode(message), Encoding.UTF8, MediaType))
{
using (var response = await HTTPClient.PostAsync(URL, content))
{
return response.IsSuccessStatusCode
? await response.Content.ReadAsByteArrayAsync()
: null;
}
}
}
catch (Exception)
{
return null;
}
}
 
///////////////////////////////////////////////////////////////////////////
// Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
/// <summary>
/// Sends a GET request to an URL with set key-value pairs.
/// </summary>
/// <param name="URL">the url to send the message to</param>
@@ -444,5 +313,10 @@
return null;
}
}
 
public void Dispose()
{
HTTPClient?.Dispose();
}
}
}