123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Threading.Tasks;
- using WCS.API.Helper;
- using WCS.API.Model;
- namespace WCS.API.WebApiClient
- {
- public class WcsApi
- {
- private static RestApi<DataResponse> restApi = new RestApi<DataResponse>();
- private static RestApi<DataResponseSPS> restApiSPS = new RestApi<DataResponseSPS>();
- private static RestApi<DataResponseMES> restApiMES = new RestApi<DataResponseMES>();
- public static bool Post(string url, object pars, object body, out string data, out string msg)
- {
- data = default(string);
- msg = default(string);
- try
- {
- DataResponse res = restApi.Post(url, pars, body, out string content);
- if (res.Success)
- {
- msg = res.Msg;
- data = res.Response;
- return res.Success;
- }
- }
- catch (Exception ex)
- {
- MsgDisplayHelper.Instance.DisplayError(ex.ToString());
- }
- return false;
- }
- public static void GetTrafficArea(string url, object pars, object body, out DataResponseTraffic res)
- {
- res = null;
- try
- {
- restApiSPS.Get(url, pars, body, out string content);
- }
- catch (Exception ex)
- {
- MsgDisplayHelper.Instance.DisplayError(ex.ToString());
- }
- }
- public static void PostSPS(string url, object pars, object body, out DataResponseSPS res)
- {
- res = null;
- try
- {
- res = restApiSPS.Post(url, pars, body, out string content);
- }
- catch (Exception ex)
- {
- MsgDisplayHelper.Instance.DisplayError(ex.ToString());
- }
- }
- public static void PostMES(string url, object pars, object body, out DataResponseMES res)
- {
- res = null;
- try
- {
- res = restApiMES.Post(url, pars, body, out string content);
- }
- catch (Exception ex)
- {
- MsgDisplayHelper.Instance.DisplayError(ex.ToString());
- }
- }
- public static String GetData(String url)
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
- request.Method = "GET";
- request.ContentType = "text/html, application/xhtml+xml, */*";
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- Stream rs = response.GetResponseStream();
- StreamReader sr = new StreamReader(rs, Encoding.UTF8);
- var result = sr.ReadToEnd();
- sr.Close();
- rs.Close();
- return result;
- }
- }
- }
|