Click here to Skip to main content
15,891,905 members
Home / Discussions / C#
   

C#

 
GeneralPlz help Pin
alok_2k327-Feb-08 2:36
alok_2k327-Feb-08 2:36 
GeneralRe: Plz help Pin
Not Active27-Feb-08 2:40
mentorNot Active27-Feb-08 2:40 
GeneralRe: Plz help Pin
alok_2k327-Feb-08 3:23
alok_2k327-Feb-08 3:23 
GeneralRepost. Ignore message. Pin
J4amieC27-Feb-08 2:41
J4amieC27-Feb-08 2:41 
GeneralRe: Plz help Pin
Paul Conrad27-Feb-08 3:49
professionalPaul Conrad27-Feb-08 3:49 
GeneralRe: Plz help Pin
Le centriste27-Feb-08 4:24
Le centriste27-Feb-08 4:24 
GeneralRe: Plz help Pin
Paul Conrad27-Feb-08 6:55
professionalPaul Conrad27-Feb-08 6:55 
QuestionhttpWebRequest issue Pin
pelgrim_198327-Feb-08 2:34
pelgrim_198327-Feb-08 2:34 
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
{
///
/// The main entry point for the application.
///

[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.
GeneralByte[], alternate null chars Pin
Malcolm Smart27-Feb-08 2:30
Malcolm Smart27-Feb-08 2:30 
GeneralRe: Byte[], alternate null chars Pin
Bekjong27-Feb-08 2:55
Bekjong27-Feb-08 2:55 
GeneralRe: Byte[], alternate null chars Pin
Malcolm Smart27-Feb-08 3:01
Malcolm Smart27-Feb-08 3:01 
GeneralRe: Byte[], alternate null chars Pin
Bekjong27-Feb-08 3:14
Bekjong27-Feb-08 3:14 
GeneralRe: Byte[], alternate null chars Pin
Malcolm Smart27-Feb-08 3:37
Malcolm Smart27-Feb-08 3:37 
GeneralRe: Byte[], alternate null chars Pin
Bekjong27-Feb-08 3:47
Bekjong27-Feb-08 3:47 
GeneralAre child threads of an object destroyed when an object is destroyed. Pin
Sunset Towers27-Feb-08 2:26
Sunset Towers27-Feb-08 2:26 
GeneralRe: Are child threads of an object destroyed when an object is destroyed. Pin
Roger Alsing27-Feb-08 2:35
Roger Alsing27-Feb-08 2:35 
GeneralRe: Are child threads of an object destroyed when an object is destroyed. Pin
Not Active27-Feb-08 2:39
mentorNot Active27-Feb-08 2:39 
GeneralRe: Are child threads of an object destroyed when an object is destroyed. Pin
Bekjong27-Feb-08 2:41
Bekjong27-Feb-08 2:41 
GeneralRe: Are child threads of an object destroyed when an object is destroyed. Pin
pbraun27-Feb-08 9:09
pbraun27-Feb-08 9:09 
GeneralSpeech comparison Pin
Yoyosch27-Feb-08 2:24
Yoyosch27-Feb-08 2:24 
GeneralRe: Speech comparison Pin
mav.northwind27-Feb-08 3:39
mav.northwind27-Feb-08 3:39 
GeneralRe: Speech comparison Pin
Yoyosch27-Feb-08 3:49
Yoyosch27-Feb-08 3:49 
GeneralRe: Speech comparison Pin
Justin Perez27-Feb-08 4:02
Justin Perez27-Feb-08 4:02 
QuestionHow to write properties in design time Pin
El'Cachubrey27-Feb-08 2:15
El'Cachubrey27-Feb-08 2:15 
AnswerRe: How to write properties in design time Pin
Xmen Real 27-Feb-08 2:33
professional Xmen Real 27-Feb-08 2:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.