HttpWebRequest
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 18

Thread: HttpWebRequest

Threaded View

  1. #1
    Join Date
    Nov 2010
    Posts
    9

    Question HttpWebRequest

    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:
    Code:
    try
    {
    	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);
    	dataStream.Close();
    
    	WebResponse mineRes = mineReq.GetResponse();
    	dataStream = mineRes.GetResponseStream();
    	StreamReader reader = new StreamReader(dataStream);
    
    	XmlDocument mineXML = new XmlDocument();
    	mineXML.Load(reader.ReadToEnd());
    
    	reader.Close();
    	dataStream.Close();
    	mineRes.Close();
    
    	// XmlDocument readXML = new XmlDocument();
    	// readXML.Load(mineReq.GetResponse().GetResponseStream());
    }
    catch(Exception exp)
    {
    	Console.WriteLine(exp.Message);
    }
    what am I doing wrong?
    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!!!
    Attached Files Attached Files

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center