Project files for the Acumatica Import for United Rentals
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Net;
  3. using System.Net.Http;
  4. using System.Net.Http.Headers;
  5. using Acumatica.RESTClient.Client;
  6. namespace uri_import.AClasses
  7. {
  8. public class RestService : IDisposable
  9. {
  10. private readonly HttpClient _httpClient;
  11. private readonly string _acumaticaBaseUrl;
  12. public RestService(string acumaticaBaseUrl)
  13. {
  14. _acumaticaBaseUrl = acumaticaBaseUrl;
  15. _httpClient = new HttpClient(new HttpClientHandler
  16. {
  17. UseCookies = true,
  18. CookieContainer = new System.Net.CookieContainer()
  19. })
  20. {
  21. BaseAddress = new Uri(acumaticaBaseUrl + "/entity/Default/20_200_001/"),
  22. DefaultRequestHeaders = { Accept = { MediaTypeWithQualityHeaderValue.Parse("text/json") } }
  23. };
  24. }
  25. public RestService(string acumaticaBaseUrl, string userName, string password, string tenant, string locale)
  26. {
  27. _acumaticaBaseUrl = acumaticaBaseUrl;
  28. _httpClient = new HttpClient(new HttpClientHandler
  29. {
  30. UseCookies = true,
  31. CookieContainer = new System.Net.CookieContainer()
  32. })
  33. {
  34. BaseAddress = new Uri(acumaticaBaseUrl + "/entity/Default/20_200_001/"),
  35. DefaultRequestHeaders = { Accept = { MediaTypeWithQualityHeaderValue.Parse("text/json") } }
  36. };
  37. _httpClient.PostAsJsonAsync(acumaticaBaseUrl + "/entity/auth/login", new
  38. {
  39. name = userName,
  40. password = password,
  41. tenant = tenant,
  42. locale = locale
  43. }).Result
  44. .EnsureSuccessStatusCode();
  45. }
  46. public string PutFile(string acumaticaBaseUrl, string entityName, string keys, string fileName, System.IO.Stream file)
  47. {
  48. string endPoint = string.Format("{0}/{1}/{2}/{3}/files/{4}", acumaticaBaseUrl, "/entity/Default/20.200.001/", entityName, keys, fileName);// +"/entity/Default/20.200.001/" + entityName + "/" + keys + "/files/" + fileName;
  49. var res = _httpClient.PutAsync(endPoint, new StreamContent(file)).Result.EnsureSuccessStatusCode();
  50. return res.Content.ReadAsStringAsync().Result;
  51. }
  52. void IDisposable.Dispose()
  53. {
  54. _httpClient.PostAsync(_acumaticaBaseUrl + "/entity/auth/logout",
  55. new ByteArrayContent(new byte[0])).Wait();
  56. _httpClient.Dispose();
  57. }
  58. }
  59. }