Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

httpWebRequest issue

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gerbrand colombier - 27 Feb 2008 13:33 GMT
Hello,

I hope somebody has a good explanation for this issue.

Okay I'm having troubles with the httpWebRequest method. I need to
download reports from a specified server (can't give these details). Now
I don't have trouble with an "HTTPS" url but I with an "HTTP" url I get
the error :

error: The server committed a protocol violation. Section=ResponseHeader
Detail=Header name is invalid

This the first time I got this error in c#.net. I tried this in Java and
there I didn't had any problems. So I'm kind of lost.

I search the internet to see what the "ProtocolViolationException"
throws. I found this on the msdn site:

ProtocolViolationException :
Method is GET or HEAD, and either ContentLength is greater or equal to
zero or SendChunked is true.
-or-
KeepAlive is true, AllowWriteStreamBuffering is false, ContentLength is
-1, SendChunked is false, and Method is POST or PUT.

I did an output of these properties and some how these don't have the
values mention to trigger the ProtocolViolationException.

So my question is, How is this possible?

this is my testClass:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;

namespace adlogix_views
{
   static class httpTestClass
   {
       /// <summary>
       /// The main entry point for the application.
       /// </summary>
       [STAThread]
       static void Main()
       {
         
           string page = "";
           try
           {              
               // write a line of text to the file
               HttpWebRequest wr =
(HttpWebRequest)WebRequest.Create("http://www.mywebsite.com");

               string userPass = "myUsername:myPassword";
               string encoding =
Convert.ToBase64String(Encoding.ASCII.GetBytes(userPass));

               wr.Headers.Add("Authorization", "Basic " + encoding);
               wr.PreAuthenticate = true;

               Console.WriteLine("Method = " + wr.Method);
               Console.WriteLine("ContentLength = " +
wr.ContentLength);
               Console.WriteLine("SendChunked = " + wr.SendChunked);
               Console.WriteLine("KeepAlive = " + wr.KeepAlive);
               Console.WriteLine("AllowWriteStreamBuffering = " +
wr.AllowWriteStreamBuffering);

               HttpWebResponse ws = (HttpWebResponse)wr.GetResponse();
               Stream str = ws.GetResponseStream();
               StreamReader sr = new StreamReader(str);
               while ((page = sr.ReadLine()) != null)
               {
                   Console.WriteLine(page);
               }

           }
           catch (Exception ex)
           {
               Console.WriteLine(ex.Message);
           }
       }
   }
}

this is the output of the properties

output: Method = GET
       ContentLength = -1
       SendChunked = False
       KeepAlive = True
       AllowWriteStreamBuffering = True

I hope somebody can help me with this.
Jon Skeet [C# MVP] - 27 Feb 2008 13:40 GMT
> I hope somebody has a good explanation for this issue.
>
[quoted text clipped - 23 lines]
>
> So my question is, How is this possible?

You've written out the *request* properties. If it's saying that the
*server* committed a protocol violation, that would suggest that it's
the *response* which is invalid.

Personally at this stage, I usually run WireShark to see what's
actually coming back over the network.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.