public string GenerateHttpClientCode() { var template = new GenerateCode(); //template.Session = new Dictionary<string, object>(){ { "SelectedSession",this.__selectedSession }}; template.Session = new Dictionary <string, object>(); template.Session.Add("uri", this.__selectedSession.fullUrl); template.Session.Add("host", this.__selectedSession.host); template.Session.Add("httpmethod", this.__selectedSession.RequestMethod); #region Add HttpHeaders var headers = new Dictionary <string, string>(); foreach (var item in this.__selectedSession.oRequest.headers) { headers.Add(item.Name, item.Value); } #endregion template.Session.Add("headers", headers); template.Initialize(); var generatedCode = template.TransformText(); return(generatedCode); }
public string GenerateHttpClientCode() { var template = new GenerateCode(); template.Session = new Dictionary <string, object>(); template.Session.Add("uri", (this.__selectedSession.isHTTPS ? "https" : "http") + "://" + this.__selectedSession.host + this.__selectedSession.PathAndQuery); //template.Session.Add("host", this.__selectedSession.host); template.Session.Add("httpmethod", this.__selectedSession.RequestMethod); #region Add HttpHeaders var headers = new Dictionary <string, string>(); if (this.__menuItemNoHeader.Checked) { foreach (var item in this.__selectedSession.oRequest.headers) { headers.Add(item.Name, item.Value); } } #endregion template.Session.Add("headers", headers); string queryString = null; //string path = this.__selectedSession.PathAndQuery; if (this.__selectedSession.RequestMethod.ToUpperInvariant() == WebRequestMethods.Http.Post) { queryString = this.__selectedSession.GetRequestBodyAsString(); } //template.Session.Add("uri", path); var bodies = new Dictionary <string, string>(); #region Add bodies if (!string.IsNullOrWhiteSpace(queryString)) { NameValueCollection x = HttpUtility.ParseQueryString(queryString); try { foreach (var item in x.AllKeys) { if (string.IsNullOrWhiteSpace(x[item])) { continue; } bodies.Add(item, x[item]); } } catch { bodies.Clear(); } } #endregion template.Session.Add("bodies", bodies); template.Initialize(); var generatedCode = template.TransformText(); return(generatedCode); }