Import Data


C# .NET 4.5 Example

using System;
using System.Text;
using System.Net.Http;
using System.IO;

namespace fn_dotnet_examples
{
	class Program
	{
		private static string url = "https://test.factorsnetwork.com/api/creditors/f386c06a-ff8f-42e9-946e-a9e88fd3eaed/data/2013-08.json";
		private static string username = "USERNAME";
		private static string password = "PASSWORD";
		private static string file = @"Full_path_to_file";

		static void Main(string[] args)
		{
			HttpResponseMessage message;
			var authContent = Convert.ToBase64String(Encoding.Default.GetBytes(username + ":" + password));

			using (HttpClient client = new HttpClient())
			using (var formData = new MultipartFormDataContent())
			using (HttpContent content = new ByteArrayContent(File.ReadAllBytes(file)))
			{
				client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", authContent);
				formData.Add(content, "file", Path.GetFileName(file));
				var response = client.PostAsync(url, formData);
				message = response.Result;
			}

			Console.WriteLine(message.IsSuccessStatusCode);
			if (message.IsSuccessStatusCode)
			{
				Console.WriteLine(message.Content.ReadAsStringAsync().Result);
			}

			Console.WriteLine("Press any key to exit.");
			Console.ReadKey();
		}
	}
}