CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18

Thread: HttpWebRequest

  1. #16
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: HttpWebRequest

    interestingly it works when you put all the parameters in the call to Create the instance of HttpWebRequest like this:
    Code:
    HttpWebRequest httpWebRequest = 
       (HttpWebRequest)WebRequest.Create("http://friendfeed-api.com/v2/entry?body=Hello API&format=xml");
    and skips the line
    Code:
    Stream dataStream = httpWebRequest.GetRequestStream();
    "Hallo API" was successfuly added to my feed
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  2. #17
    Join Date
    Nov 2010
    Posts
    9

    Re: HttpWebRequest

    will you post the code here?

    why does this happen?!

  3. #18
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: HttpWebRequest

    Quote Originally Posted by nutrione View Post
    will you post the code here?
    sure, here it is:
    Code:
    using System;
    using System.IO;
    using System.Net;
    using System.Xml.Linq;
    
    namespace ConsoleApplication2
    {
        class Program
        {
            static void Main(string[] args)
            {
                HttpWebRequest httpWebRequest = 
    		(HttpWebRequest)WebRequest.Create("http://friendfeed-api.com/v2/entry?body=Hello API&format=xml");
                httpWebRequest.KeepAlive = false;
                httpWebRequest.ProtocolVersion = HttpVersion.Version10;
                httpWebRequest.Credentials = new NetworkCredential("***", "****");
                httpWebRequest.Method = "POST";
                httpWebRequest.ContentType = "multipart/form-data";
                httpWebRequest.ContentLength = 0;
    
                using (WebResponse webResponse = httpWebRequest.GetResponse())
                using (Stream dataStream = webResponse.GetResponseStream())
                using (StreamReader streamReader = new StreamReader(dataStream))
                {
                    string response = streamReader.ReadToEnd();
                    XDocument xDoc = XDocument.Parse(response);    
                }
            }
        }
    }
    Quote Originally Posted by nutrione View Post
    why does this happen?!
    I have no idea maybe there is someone else who knows? guys
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

Page 2 of 2 FirstFirst 12

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
  •  





Click Here to Expand Forum to Full Width

Featured