Reading from a controller by HTTP

S

Sonnich Jensen

I have tried a number of ways and I get this error:

The server committed a protocol violation. Section=ResponseStatusLine

I am reading a CSV file from a deprag controller running linux.

My code on win7 is as follows:



textBox2.Text = "starting...";
try
{
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create(textBox1.Text);
textBox1.Text = http://200.200.200.101/cgi-bin/cgiread?site=13&dlfile=/mnt/mmc/finaldata/Actual.csv

// Set some reasonable limits on resources used by
this request
request.ServicePoint.Expect100Continue = false;
request.MaximumAutomaticRedirections = 4;
request.MaximumResponseHeadersLength = 4;

WebResponse response =
(WebResponse)request.GetResponse(); // crashes here
fromcache.Checked = response.IsFromCache;

long length = response.ContentLength;
string contentType = response.ContentType;

// Get the stream associated with the response.
Stream receiveStream = response.GetResponseStream();

// Pipes the stream to a higher level stream reader
with the required encoding format.
StreamReader readStream = new
StreamReader(receiveStream, Encoding.UTF8);

label2.Text = readStream.ReadToEnd();

response.Close();
readStream.Close();

textBox2.Text = "completed!";
}
catch (Exception ee)
{
textBox2.Text = ee.Message;
}
 
S

Sonnich Jensen

I have tried a number of ways and I get this error:

The server committed a protocol violation. Section=ResponseStatusLine

I am reading a CSV file from a deprag controller running linux.

My code on win7 is as follows:

            textBox2.Text = "starting...";
            try
            {
                HttpWebRequest request =
(HttpWebRequest)WebRequest.Create(textBox1.Text);
textBox1.Text =http://200.200.200.101/cgi-bin/cgiread?site=13&dlfile=/mnt/mmc/finald...

                // Set some reasonable limits on resources used by
this request
                request.ServicePoint.Expect100Continue = false;
                request.MaximumAutomaticRedirections = 4;
                request.MaximumResponseHeadersLength = 4;

                WebResponse response =
(WebResponse)request.GetResponse(); // crashes here
                fromcache.Checked = response.IsFromCache;

                long length = response.ContentLength;
                string contentType = response.ContentType;

                // Get the stream associated with the response.
                Stream receiveStream = response.GetResponseStream();

                // Pipes the stream to a higher level stream reader
with the required encoding format.
                StreamReader readStream = new
StreamReader(receiveStream, Encoding.UTF8);

                label2.Text = readStream.ReadToEnd();

                response.Close();
                readStream.Close();

                textBox2.Text = "completed!";
            }
            catch (Exception ee)
            {
                textBox2.Text = ee.Message;
            }

and the file read contains of one line only:

06.10.2009,10:22:16,1,1,2.1,0,0.0,0,0,0.0,0,0,0.0,0,1,0.0,1437,0,0/0,Ncm,deg

works in any browser
 
B

bradbury9

El jueves 8 de marzo de 2012 16:47:57 UTC+1, Sonnich Jensen escribió:
and the file read contains of one line only:

06.10.2009,10:22:16,1,1,2.1,0,0.0,0,0,0.0,0,0,0.0,0,1,0.0,1437,0,0/0,Ncm,deg

works in any browser

I would:
- Check http server log to check if the respose status code is the expected(200).
- Sniff http request and server response to find out strange things

Seems like the server is not returning a valid http status code or a not supported one.

http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
 
B

bradbury9

El jueves 8 de marzo de 2012 16:58:47 UTC+1, bradbury9 escribió:
El jueves 8 de marzo de 2012 16:47:57 UTC+1, Sonnich Jensen escribió:

I would:
- Check http server log to check if the respose status code is the expected (200).
- Sniff http request and server response to find out strange things

Seems like the server is not returning a valid http status code or a not supported one.

http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

You can check the .net framework supported status codes at msdn: http://msdn.microsoft.com/en-us/library/system.net.httpstatuscode.aspx

Proxy settings and user autentification are usually things to take into consideration that can make IE and FF showing content right and .NET giving exceptions. But I think it is a differet one because of the "protocol violation. Section=ResponseStatus" message.
 
A

Arne Vajhøj

I have tried a number of ways and I get this error:

The server committed a protocol violation. Section=ResponseStatusLine

I am reading a CSV file from a deprag controller running linux.

My code on win7 is as follows:



textBox2.Text = "starting...";
try
{
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create(textBox1.Text);
textBox1.Text = http://200.200.200.101/cgi-bin/cgiread?site=13&dlfile=/mnt/mmc/finaldata/Actual.csv

You use textBox1.Text before giving it a value??

Arne
 
S

Sonnich Jensen

You use textBox1.Text before giving it a value??

No, it has the value given here - as you see the quotes are missing.
The textbox is so I can use my range of Deprag's, I have 10 of them
with different IPs....
 
S

Sonnich Jensen

El jueves 8 de marzo de 2012 16:58:47 UTC+1, bradbury9  escribió:













You can check the .net framework supported status codes at msdn:http://msdn.microsoft.com/en-us/library/system.net.httpstatuscode.aspx

Proxy settings and user autentification are usually things to take into consideration that can make IE and FF showing content right and .NET giving exceptions. But I think it is a differet one because of the "protocol violation. Section=ResponseStatus" message.

Well, the GetResponse crashes, so I never get any code.
The value does not get set, so I dont get any data....
 
B

bradbury9

El viernes 9 de marzo de 2012 12:50:07 UTC+1, Sonnich Jensen escribió:
Well, the GetResponse crashes, so I never get any code.
The value does not get set, so I dont get any data....

That is the reason I told you to check the server logs or sniff the http trafic between the client and the server ;-)
 
B

bradbury9

I would also have checked if the URL is correct, because the argument
dlfile=/mnt/mmc/finaldata/Actual.csv soes not seem to be a Linux file
path (which would use \mnt\mmc\... )

You are wrong. Linux path delimiter is / and you tell him it is \ so file path would be /mnt/mmc/...

May be strange, but is one thing I like about Linux, Unix and BSD OS's.


BTW: that absolute path looks like a nasty security bug.
 
B

bradbury9

BTW: that absolute path looks like a nasty security bug.
Absolutely, but I doubt that any webserver would give root access, which
again raises the question: Are you sure that the path are correct, -
seen from the outside?

/mnt/mmc/ seems to be some sort of card reader device mount point and most likely it would be mounted with big privileges (unless they did chgroup themount point and made it rw for apache user). If they do:

File.ReadAllBytes(dlfile);

And it works with that path you have a potencial security bug :-D
 
A

Arne Vajhøj

Den 09.03.2012 13:55, skrev bradbury9:

Sorry, I mixed a bit.

Yep.

But even if it had been the case then one usually use / in
URL's and translate to OS specific path server side. Also
for file name query parameters.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top