2 Şubat 2011 Çarşamba

sunucudaki ssl hatasını gidermek : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel

System.Net.ServicePointManager.ServerCertificateValidationCallback += delegate
(object sender, X509Certificate certificate, X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{ return true; };

var parameters = "go=1";

var cred = new NetworkCredential();
cred.Password = "demo"
cred.UserName = "admin"

var request = (HttpWebRequest)HttpWebRequest.Create("https://www.google.com");
request.AllowAutoRedirect = false;
request.ContentType = "application/x-www-form-urlencoded";
request.Credentials = cred;
request.Method = "POST";
request.UserAgent = "Vargonen/0.1";
request.ContentLength = parameters.Length;

var reqStream = request.GetRequestStream();
reqStream.Write(parameters, 0, parameters.Length);
reqStream.Close();

var response = (HttpWebResponse)request.GetResponse();
var sr = new StreamReader(response.GetResponseStream());
var htmlText = sr.ReadToEnd().Trim();

sayfadaki verileri word dosyasına aktarma

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "";

HttpContext.Current.Response.ContentType = "application/msword";

string strFileName = "GenerateDocument" + ".doc";
HttpContext.Current.Response.AddHeader("Content-Disposition",
"inline;filename=" + strFileName);

StringBuilder strHTMLContent = new StringBuilder();

strHTMLContent.Append("buraya wordde görünmesi gereken yazılar geliyor.html de kullanabilirsiniz.")
HttpContext.Current.Response.Write(strHTMLContent);
HttpContext.Current.Response.End();
HttpContext.Current.Response.Flush();