public string GetPage(HttpWebRequest request) { try { string content = null; byte[] bytes = DownloadData(request); if (bytes != null) { if (isCharsetProbe && CharsetProbe.IsValidUtf8(bytes)) { content = Encoding.UTF8.GetString(bytes); } else { content = encode.GetString(bytes); } } return(content); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(null); } }
public string GetPage(Uri uri, string referer, int timeOut) { try { string content = null; byte[] bytes = DownloadData(uri, referer, timeOut); if (bytes != null) { if (isCharsetProbe && CharsetProbe.IsValidUtf8(bytes)) { content = Encoding.UTF8.GetString(bytes); } else { content = encode.GetString(bytes); } } return(content); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(null); } }
public string Post(HttpWebRequest request, byte[] bytes) { HttpWebResponse response = null; try { string content = null; Stream requestStream = request.GetRequestStream(); requestStream.Write(bytes, 0, bytes.Length); requestStream.Close(); response = (HttpWebResponse)request.GetResponse(); bytes = ResponseAsBytes(response); if (bytes != null) { if (CharsetProbe.IsValidUtf8(bytes)) { content = Encoding.UTF8.GetString(bytes); } else { content = encode.GetString(bytes); } } return(content); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(null); } finally { if (response != null) { response.Close(); response = null; } request = null; } }