viernes, agosto 05, 2005

Modificaciones en Atom.lib

Bueno a pedido del publico y despues de mucho tiempo de inactividad me puse a trabajar hoy en la mañana (hace un par de horas) y realize algunas modificaciones a la libreria de Gmikex. Esta vez el codigo es mucho mas sencillo, aunque por si las moscas (jeje nunca falta :P) le he incorparado comentarios ;)


using System;
using System.Net;
using System.IO;
using System.Xml;
using System.Collections;
using System.Security.Cryptography.X509Certificates;

class atom
{

//Author: NeCuDeCo
public static void Main(String[] args)
{
if (args.Length != 2)
{
//La ejecucion del programa requeire que se el pase dos argumentos obligatorios, el nombvre usuario de blogger y si contraseña
Console.WriteLine("mono atom.exe ");
return;
}

string usuario = args[0];
string passwd = args[1];

//Presentandome ante blogger como el usuario y obteniendo la lista de servicios
atom a = new atom();
string stringXML = a.getfeed("http://www.blogger.com/atom",usuario,passwd);

XmlTextReader xml = new XmlTextReader(new StringReader(stringXML));

XmlDocument doc = new XmlDocument();
doc.Load(xml);
XmlNode node = doc.DocumentElement;

foreach ( XmlNode subnode in node.ChildNodes)
{

if ( subnode.LocalName == "link" )
{
//Buscando y Reportando los Servicios o blogs donde puedo postear
XmlElement xnode = (XmlElement) subnode;
if (xnode.GetAttribute("rel") == "service.post")
Console.WriteLine(xnode.GetAttribute("title"));
}

}
}


//funcion Definida por Gmikex para obtener la lista de servicios de blogguer.
//Modificaciones de NeCuDeCo
public string getfeed(string url,string login, string passwd){
string responseString="";
try{
HttpWebRequest myReq = (HttpWebRequest) HttpWebRequest.Create(url);
myReq.PreAuthenticate =true;

NetworkCredential networkCredential=new NetworkCredential(login,passwd);
myReq.Credentials=networkCredential;

HttpWebResponse response = (HttpWebResponse)myReq.GetResponse();
Stream streamResponse = response.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
responseString = streamRead.ReadToEnd();
return responseString;
}catch(Exception ex){
Console.WriteLine("ERROR");
return responseString;
}
}
}