download BloggerBlog.cs
Language: C#
LOC: 48
Project Info
XPost
Server: Spider_20090529_inc
Type: filesystem
...xpost‑0.02.zip.‑‑‑\release\
   AccountManagementWindow.cs
   AddAccountWindow.cs
   AssemblyInfo.cs
   Blog.cs
   BloggerBlog.cs
   BloggerUser.cs
   BlogList.cs
   BlogUser.cs
   HTTPClient.cs
   LivejournalBlog.cs
   LivejournalUser.cs
   LivespacesUser.cs
   Main.cs
   MainWindow.cs
   MetaweblogBlog.cs
   MetaweblogUser.cs
   MyspaceBlog.cs
   MyspaceUser.cs
   PostView.cs
   ...llCertificatesPolicy.cs
   Util.cs
   WordpressUser.cs
   XangaBlog.cs
   XangaUser.cs
   XPostUser.cs

using System;
using System.Net;
using System.IO;

namespace XPost
{
	
	
	public class BloggerBlog : Blog 
	{
		private string posturl;
		private string name;
		
		public BloggerBlog(BloggerUser parent, string posturl, string name) : base(parent)
		{
			this.posturl = posturl;
			this.name = name;	
		}
		
		public override bool doPost(string subject, string body) {
		
			Console.WriteLine(this.posturl);
		
			HttpWebRequest wr = (HttpWebRequest) HttpWebRequest.Create(this.posturl);
		
			wr.Method = "POST";
			wr.AllowAutoRedirect = true;
			wr.Headers.Add("Authorization","GoogleLogin auth=" + ((BloggerUser)this.parent).authString);
			
			StreamWriter sw = new StreamWriter(wr.GetRequestStream());
			sw.Write(this.buildPost(subject, body));
			sw.Close();
			
			HttpWebResponse hwr;
			try {
				hwr = (HttpWebResponse) wr.GetResponse();
			} catch(WebException e) {
				hwr = (HttpWebResponse) e.Response;
			}
		
			if(hwr.StatusCode == System.Net.HttpStatusCode.Created) {
				return true;
			}
		
			return false;
		}
		
		public override string shortName() {
			return this.name + " (" + this.parent.username + ")";
		}
		
		private string buildPost(string subject, string body) {
		
			string ret = "";
			
			ret =      "<entry xmlns='http://www.w3.org/2005/Atom'>";
			ret = ret + "<title type='text'>" + subject +"</title>";
			ret = ret + "<content type='html'>" + body + "</content>";
			ret = ret + "<author><name>" + ((BloggerUser)this.parent).realname +"</name>"; 
			ret = ret + "<email>" + this.parent.username + "</email></author></entry>";
			return ret;
		}
	}
}

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us