Re: bug in clientpost.cs?

From: Dennis Myrén (dennis_at_oslokb.no)
Date: 11/17/04


Date: Wed, 17 Nov 2004 09:58:16 +0100

Add a reference to system.web.dll .

-- 
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Jensen Bredhal" <first.last@yahoo.com> wrote in message 
news:%23fvcpLIzEHA.1412@tk2msftngp13.phx.gbl...
> Hello,
>
> I have copied and paste the following sample code from VS.Net MSDN  sample
> code:
> But i can not compile it . I'm getting the following error :
>
> ...\ConsoleApplication1\Class1.cs(68): The type or namespace name
> 'HttpUtility' does not exist in the class or namespace 'System.Web' (are 
> you
> missing an assembly reference?)
>
> HttpUtility' belongs to the namespace System.web according to the doc.
>
> So i do not understand why the code can not compile.
>
>
> Any comment will be appreciated
>
>
> using System;
> using System.Net;
> using System.IO;
> using System.Text;
> using System.Web;
>
> class ClientPOST {
>    public static void Main(string[] args) {
>
>        if (args.Length < 1) {
>            showusage();
>        } else {
>            if (args.Length < 2 ) {
>                getPage(args[0], "s1=food&s2=bart");
>            } else {
>                getPage(args[0], args[1]);
>            }
>        }
>
>        Console.WriteLine();
>        Console.WriteLine("Press any key to continue...");
>        Console.ReadLine();
>
>        return;
>    }
>
>    public static void showusage() {
>        Console.WriteLine("Attempts to POST into to a URL");
>        Console.WriteLine();
>        Console.WriteLine("Usage:");
>        Console.WriteLine("ClientPOST URL [postdata]");
>        Console.WriteLine();
>        Console.WriteLine("Examples:");
>        Console.WriteLine("ClientPOST http://www.microsoft.com
> s1=food&s2=bart");
>    }
>
>    public static void getPage(String url, String payload) {
>        WebResponse result = null;
>
>        try {
>
>            WebRequest req = WebRequest.Create(url);
>            req.Method = "POST";
>            req.ContentType = "application/x-www-form-urlencoded";
>        StringBuilder UrlEncoded = new StringBuilder();
>        Char[] reserved = {'?', '=', '&'};
>        byte[] SomeBytes = null;
>
>        if (payload != null) {
>        int i=0, j;
>        while(i<payload.Length){
>            j=payload.IndexOfAny(reserved, i);
>            if (j==-1){
>            UrlEncoded.Append(HttpUtility.UrlEncode(payload.Substring(i,
> payload.Length-i)));
>            break;
>            }
>            UrlEncoded.Append(HttpUtility.UrlEncode(payload.Substring(i,
> j-i)));
>            UrlEncoded.Append(payload.Substring(j,1));
>            i = j+1;
>        }
>        SomeBytes = Encoding.UTF8.GetBytes(UrlEncoded.ToString());
>                req.ContentLength = SomeBytes.Length;
>                Stream newStream = req.GetRequestStream();
>        newStream.Write(SomeBytes, 0, SomeBytes.Length);
>                newStream.Close();
>            } else {
>                req.ContentLength = 0;
>            }
>
>
>            result = req.GetResponse();
>            Stream ReceiveStream = result.GetResponseStream();
>            Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
>            StreamReader sr = new StreamReader( ReceiveStream, encode );
>            Console.WriteLine("\r\nResponse stream received");
>            Char[] read = new Char[256];
>            int count = sr.Read( read, 0, 256 );
>            Console.WriteLine("HTML...\r\n");
>            while (count > 0) {
>                String str = new String(read, 0, count);
>                Console.Write(str);
>                count = sr.Read(read, 0, 256);
>            }
>            Console.WriteLine("");
>        } catch(Exception e) {
>            Console.WriteLine( e.ToString());
>            Console.WriteLine("\r\nThe request URI could not be found or 
> was
> malformed");
>        } finally {
>            if ( result != null ) {
>                result.Close();
>            }
>        }
>    }
> }
>
>
> 


Relevant Pages

  • Re: custom namespaces
    ... and for which I think I must need to compile ... it so that the code behind can actually see/find reference to the custom ... I'm trying to create custom a namespace for use ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Bug in Clientpost.cs?
    ... Add a reference to system.web.dll. ... > HttpUtility' belongs to the namespace System.web according to the doc. ... > So i do not understand why the code can not compile. ... > public static void Main{ ...
    (microsoft.public.dotnet.general)
  • Re: Where is System.Collections when using csc.exe
    ... Namespaces are not required to have their types completely contained within an assembly, so asking where the types for a namespace are located doesn't make much sense. ... By default, csc should make a reference to mscorlib.dll automatically, so it seems like it should work to me. ... If you compile this from the command line yourself, ... Visual Studio C# Express 2005 doesn't have a problem with them though, and can compile my code without errors. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Old website mix with asp.net 2
    ... I tried to create the new website in VS 2005, then add my new aspx pages, it fine, I can compile and run. ... I want to include the "Employee" namespace in the using clause but the compilar did not find that. ... When you want to use classes defined in an external assembly, you must add a reference to it in your project. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Creating a custom class/Namespace
    ... >> How then would I reference this in a new Web Application ... To compile a single source code file, ... If you need to reference a .Net Framework assembly or assemblies, ... I get the message in the compiler output that my namespace ...
    (microsoft.public.dotnet.framework.aspnet)