示例#1
0
        private ApiResult <T> ApiTokenCall <T>(string guest_token, string action_url, Dictionary <string, object> args = null)
        {
            var _result = new ApiResult <T>()
            {
                success = false,
                message = "",
                result  = default(T)
            };

            try
            {
                var _request = new NSMutableUrlRequest(NSUrl.FromString($"{Constants.LionApiUrl}{action_url}"));
                _request.HttpMethod = "POST";

                _request.Headers = NSDictionary.FromObjectsAndKeys(
                    new object[] { $"Bearer {guest_token}" },
                    new object[] { "Authorization" }
                    );

                if (args != null)
                {
                    var _request_body = "";
                    foreach (var a in args)
                    {
                        if (_request_body != "")
                        {
                            _request_body += "&";
                        }
                        _request_body += $"{a.Key}={a.Value}";
                    }

                    _request.Body = _request_body;
                }

                var _response = (NSUrlResponse)null;
                var _error    = (NSError)null;

                var _url_data = this.ApiCallAsync(_request, ref _response, ref _error);
                if (_error != null)
                {
                    NSLogHelper.NSLog($"apiTokenCall error: {_error}");
                    _result.message = _error.ToString();
                }
                else
                {
                    _result = JsonConvert.DeserializeObject <ApiResult <T> >(_url_data.ToString());
                }
            }
            catch (Exception ex)
            {
                ConfigHelper.ShowConfirm("오류", "서버가 응답하지 않습니다.\n 잠시 후 다시 시도해주시기 바랍니다.", "확인");
                _result.message = ex.ToString();
            }

            return(_result);
        }
示例#2
0
        private ApiResult <T> ApiPostCall <T>(string action_url)
        {
            var _result = new ApiResult <T>()
            {
                success = false,
                message = "",
                result  = default(T)
            };

            try
            {
                var _request = new NSMutableUrlRequest(NSUrl.FromString($"{Constants.LionApiUrl}{action_url}"));
                _request.HttpMethod = "POST";

                var _response = (NSUrlResponse)null;
                var _error    = (NSError)null;

                var _url_data = this.ApiCallAsync(_request, ref _response, ref _error);
                if (_error != null)
                {
                    NSLogHelper.NSLog($"apiPostCall error: {_error}");
                    _result.message = _error.ToString();
                }
                else
                {
                    _result = JsonConvert.DeserializeObject <ApiResult <T> >(_url_data.ToString());
                }
            }
            catch (Exception ex)
            {
                ConfigHelper.ShowConfirm("오류", "서버가 응답하지 않습니다.\n 잠시 후 다시 시도해주시기 바랍니다.", "확인");
                _result.message = ex.ToString();
            }

            return(_result);
        }