public static FileExportResult ExportFile(ForwardRequestData requestData, string exporterName) { string svcHost = System.Configuration.ConfigurationManager.AppSettings["SVCHost"]; string url = string.Format("http://" + svcHost + "{0}/{1}", (requestData.Port.HasValue ? (":" + requestData.Port) : string.Empty), requestData.Url.TrimStart('\\', '/')); string method = requestData.HttpMethod.ToUpper(); if (method == "GET" && requestData.Parameters != null && requestData.Parameters.Count > 0) { string firstChar = url.Contains("?") ? "&" : "?"; int i = 0; foreach (var p in requestData.Parameters) { if (i == 0) { url = url + firstChar; } else { url = url + "&"; } url = url + p.Code + "=" + HttpUtility.UrlEncode(p.Name); i++; } } HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = method; if (method == "POST") { request.ContentType = requestData.HttpContentType; if (requestData.Parameters != null && requestData.Parameters.Count > 0) { foreach (var p in requestData.Parameters) { request.Headers[p.Code] = p.Name; } } if (requestData.Content != null && requestData.Content.Trim().Length > 0) { using (StreamWriter stream = new StreamWriter(request.GetRequestStream())) { stream.Write(requestData.Content.Trim()); } } } using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (Stream receiveStream = response.GetResponseStream()) { using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8)) { string dataString = readStream.ReadToEnd(); readStream.Close(); receiveStream.Close(); response.Close(); #region 特殊字符替换 有待补充 if (dataString.IndexOf(">") != -1) { dataString = dataString.Replace(">", ">"); } if (dataString.IndexOf("<") != -1) { dataString = dataString.Replace("<", "<"); } if (dataString.IndexOf(""") != -1) { dataString = dataString.Replace(""", "\""); } if (dataString.IndexOf("&") != -1) { dataString = dataString.Replace("&", "&"); } #endregion FileExportResult result = new FileExportResult(); //if (dataString.Contains("ServiceError") && dataString.Contains("Faults") // && dataString.Contains("StatusCode") && dataString.Contains("StatusDescription")) //导出的时候抛出BizException没有包含"ServiceError" if (dataString.Contains("Faults") && dataString.Contains("StatusCode") && dataString.Contains("StatusDescription")) { result.RestServiceError = dataString; } else { List <List <ColumnData> > clist; if (requestData == null || requestData.ColumnSetting == null) { clist = new List <List <ColumnData> >(0); } else { clist = requestData.ColumnSetting; } result.DownloadUrl = SaveFile(dataString, exporterName, clist, requestData.TextInfoList, requestData.Url); } return(result); } } } }
public FileExportResult ExportFile(ForwardRequestData requestData) { return(DataFileExporter.ExportFile(requestData, requestData.ExporterName)); }