/// <summary> /// /// </summary> /// <param name="method"></param> /// <param name="url"></param> /// <param name="body"></param> /// <param name="headersAction"></param> /// <exception cref="T:System.Net.Http.HttpRequestException"> /// 由于基础问题(如网络连接性、DNS 失败、服务器证书验证或超时),请求失败。 /// </exception> /// <returns></returns> public async Task <RestResponse> Send(HttpMethod method, string url, HttpContent body, Action <HttpRequestHeaders> headersAction = null) { //请求行 if (!string.IsNullOrEmpty(_config.BaseUrl)) { //baseUrl 和 url参数必需用 / 连接 url = !_config.BaseUrl.EndsWith("/") && !url.StartsWith("/") ? _config.BaseUrl + "/" + url : _config.BaseUrl + url; } HttpRequestMessage httpRequestMessage = new HttpRequestMessage(method, url); //请求体 if (body != null) { httpRequestMessage.Content = body; } //请求头 headersAction?.Invoke(httpRequestMessage.Headers); //触发事件 BeforeRequest?.Invoke(httpRequestMessage); RestResponse restResponse; //发送请求 try { HttpResponseMessage httpResponseMessage = await _httpClient.SendAsync(httpRequestMessage); restResponse = new RestResponse(httpResponseMessage); } catch (Exception e) { restResponse = new RestResponse(httpRequestMessage, e); } //触发事件 AfterResponse?.Invoke(restResponse); if (restResponse.Exception != null) { throw restResponse.Exception; } return(restResponse); }
static void dialog_Response(object o, ResponseArgs args) { if (AutoUpdateTask && args.ResponseId == ResponseType.Ok) { Task.Name = ((Entry)Builder.GetObject("EntryNombre")).Text; Task.Descript = ((Entry)Builder.GetObject("EntryDescrip")).Text; // Update tasks var catCol = (ListStore)Builder.GetObject("CatStoreInDialog"); catCol.Foreach(delegate(ITreeModel model, TreePath path, TreeIter iter) { var catId = (int)model.GetValue(iter, 0); var state = (bool)model.GetValue(iter, 2); Task.SetCategory(catId, state); return(false); }); } Dialog.Hide(); AfterResponse?.Invoke(); }