C# Post/Add BlogPost to LiveJournal.com Using


public struct blogInfo
{
        public string title;
        public string description;
}

public static class LJ
    {
        public static string NewPost(string strUserName, string strPassword, blogInfo bi)
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://www.livejournal.com/interface/xmlrpc");
            request.Method = "POST";

            string command = String.Format(
            @"<?xml version=""1.0""?><methodCall><methodName>LJ.XMLRPC.postevent</methodName><params><param><value><struct>
                <member><name>username</name>
                    <value><string>{0}</string></value>
                    </member>
                    <member><name>password</name>
                    <value><string>{1}</string></value>
                    </member>
                    <member><name>event</name>
                    <value><string>{3}
                    </string></value>
                    </member>
                    <member><name>subject</name>
                    <value><string>{2}</string></value>
                    </member>
                    <member><name>lineendings</name>
                    <value><string>pc</string></value>
                    </member>
                    <member><name>year</name>
                    <value><int>"+DateTime.Now.Year.ToString()+@"</int></value>
                    </member>
                    <member><name>mon</name>
                    <value><int>" + DateTime.Now.Month.ToString() + @"</int></value>
                    </member>
                    <member><name>day</name>
                    <value><int>" + DateTime.Now.Day.ToString() + @"</int></value>
                    </member>
                    <member><name>hour</name>
                    <value><int>" + DateTime.Now.Hour.ToString() + @"</int></value>
                    </member>
                    <member><name>min</name>
                    <value><int>" + DateTime.Now.Minute.ToString() + @"</int></value>
                    </member>
                    </struct></value>
                    </param>
                    </params>
                    </methodCall>", strUserName, strPassword, bi.title,bi.description);

            byte[] bytes = Encoding.ASCII.GetBytes(command);
            request.ContentLength = bytes.Length;
            using (var stream = request.GetRequestStream())
                stream.Write(bytes, 0, bytes.Length);

            using (var stream = new StreamReader(request.GetResponse().GetResponseStream()))
                return stream.ReadToEnd();

        }
    }

No comments:

Post a Comment