/// <summary> /// 格式化信息 /// </summary> internal void Normalize(HttpClient client, HttpContext context) { Client = client; Context = context; if (RequestData != null) { RequestData.BindContext(client, context, this); if (Method == HttpMethod.GET) { //内容转移到查询中 var str = RequestData.SerializeAsQueryString(); if (!str.IsNullOrEmpty()) { var query = Uri.Query; if (query.IsNullOrEmpty() || query == "?") { Uri = new Uri(Uri, "?" + str); } else { Uri = new Uri(Uri, query + "&" + str); } } } } }
/// <summary> /// 格式化信息 /// </summary> internal void Normalize(HttpClient client, HttpContext context) { Client = client; Context = context; if (RequestData != null) { if (ExtraRequestInfo?.ContentType.IsNullOrEmpty() == false) { RequestData?.SetContentType(ExtraRequestInfo.ContentType); } RequestData.BindContext(client, context, this); RequestData.PrepareData(); //构建URL if (client.Setting.EnableUrlTokenIdentitier && RequestData is RequestFormDataContent) { var formData = (RequestFormDataContent)RequestData; var uri = Uri.OriginalString; if (Regex.IsMatch(uri, @"{[a-z\d-_$\.\[\]]+}", RegexOptions.IgnoreCase)) { var fields = formData.ProcessedData; uri = Regex.Replace(uri, @"{([a-z\d-_$\.\[\]]+)}", _ => { string value; var key = _.GetGroupValue(1); if (fields.TryRemove(key, out value)) { formData.StringField.Remove(key); return(value); } return(_.Value); }, RegexOptions.IgnoreCase ); Uri = new Uri(uri); } } if (!AllowRequestBody) { //有查询数据,序列化到查询中。 var queryExtra = RequestData.SerializeAsQueryString(); if (!queryExtra.IsNullOrEmpty()) { var query = Uri.Query; if (!query.IsNullOrEmpty()) { query += "&" + queryExtra; } else { query = "?" + queryExtra; } Uri = new Uri(Uri, query); } } } }