November 18th, 2010, 09:20 PM
hey there! my first post ever!
first of all I'm completely new to C# and .NET programming.
background: I'm trying to write a piece of code that uses HttpWebRequest to post an entry to a friendfeed feed via it's API. it's a console application and uses HTTP Basic Authentication for Credentials.
problem: when I run the application it throws an exception-> The remote server returned an error: (404) Not Found. this happens while it's working if you try it through your browser.
you can use FF's API Test Form to see that Basic Auth and all of this works and FF API does the job.
I'm using .NET 3.5/VS2008
here is the code I've written:
what am I doing wrong?
HttpWebRequest mineReq = (HttpWebRequest)WebRequest.Create("http://friendfeed-api.com/v2/entry?");
//http://friendfeed.com/api/share/ or http://friendfeed-api.com/v2/entry both can be used
mineReq.KeepAlive = false;
mineReq.ProtocolVersion = HttpVersion.Version10;
mineReq.Credentials = new NetworkCredential("Username", "FFRemoteKey");
mineReq.Method = "POST";
String postData = "body=Hello API&format=xml";
byte Databyte = Encoding.UTF8.GetBytes(HttpUtility.UrlEncode(postData));
mineReq.ContentType = "multipart/form-data";
mineReq.ContentLength = Databyte.Length;
Stream dataStream = mineReq.GetRequestStream();
dataStream.Write(Databyte, 0, Databyte.Length);
WebResponse mineRes = mineReq.GetResponse();
dataStream = mineRes.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
XmlDocument mineXML = new XmlDocument();
// XmlDocument readXML = new XmlDocument();
the attached file is the FF C# API Library written by FF API Team. it's for API version 1. but I'm going to use version 2, so I canot use it but I though it may help!
thanks in advance
P.S. I'm not a native English! so forgive me for any language errors!!!
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!