// Send the request to the server System.Net.HttpWebResponse serverResponse = null; try { serverResponse = (System.Net.HttpWebResponse)req.GetResponse(); } catch (System.Net.WebException webExc) { response.StatusCode = 500; response.StatusDescription = webExc.Status.ToString(); response.Write(webExc.Response); response.End(); return; } // Set up the response to the client if (serverResponse != null) { response.ContentType = serverResponse.ContentType; using (Stream byteStream = serverResponse.GetResponseStream()) { // Text response if (serverResponse.ContentType.Contains("text") || serverResponse.ContentType.Contains("json") || serverResponse.ContentType.Contains("xml")) { //using (StreamReader sr = new StreamReader(byteStream)) //using (StreamReader sr = new StreamReader(byteStream, Encoding.GetEncoding(28591))) using (StreamReader sr = new StreamReader(byteStream, Encoding.GetEncoding(serverResponse.CharacterSet))) { string strResponse = sr.ReadToEnd(); response.Write(strResponse); } } else { // Binary response (image, lyr file, other binary file) BinaryReader br = new BinaryReader(byteStream); byte[] outb = br.ReadBytes((int)serverResponse.ContentLength); br.Close(); // Tell client not to cache the image since it's dynamic response.CacheControl = "no-cache"; // Send the image to the client // (Note: if large images/files sent, could modify this to send in chunks) response.OutputStream.Write(outb, 0, outb.Length); } serverResponse.Close(); } } response.End(); }
// Send the request to the server System.Net.WebResponse serverResponse = null; try { serverResponse = req.GetResponse(); } catch (System.Net.WebException webExc) { response.StatusCode = 500; response.StatusDescription = webExc.Status.ToString(); response.Write(webExc.Response); response.End(); return; } // Set up the response to the client if (serverResponse != null) { response.ContentType = serverResponse.ContentType; using (Stream byteStream = serverResponse.GetResponseStream()) { // Text response if (serverResponse.ContentType.Contains("text") || serverResponse.ContentType.Contains("json") || serverResponse.ContentType.Contains("xml")) { //using (StreamReader sr = new StreamReader(byteStream)) //using (StreamReader sr = new StreamReader(byteStream, Encoding.GetEncoding(28591))) using (StreamReader sr = new StreamReader(byteStream, Encoding.GetEncoding(serverResponse.CharacterSet))) { string strResponse = sr.ReadToEnd(); response.Write(strResponse); } } else { // Binary response (image, lyr file, other binary file) BinaryReader br = new BinaryReader(byteStream); byte[] outb = br.ReadBytes((int)serverResponse.ContentLength); br.Close(); // Tell client not to cache the image since it's dynamic response.CacheControl = "no-cache"; // Send the image to the client // (Note: if large images/files sent, could modify this to send in chunks) response.OutputStream.Write(outb, 0, outb.Length); } serverResponse.Close(); } } response.End(); }
using (StreamReader sr = new StreamReader(byteStream, Encoding.GetEncoding(28591){...}
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.idee.es/wms/IDEE-Referencia/IDEE-Referencia?request=GetCapabilities&service=WMS"); HttpWebResponse res = (HttpWebResponse)req.GetResponse(); using (StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.GetEncoding(res.CharacterSet))) { //Perform string operation here }
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.