473,324 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Dealing with bad HTTP headers

So, I'm trying to write a web spider for some data gathering from a
public database webserver. Anyway, in response to a POST, the webserver
returns "200 Script Results Follow" instead of "201 CREATED". While
both IE and Firefox ignore the odd header, this response kills my
HttpWebRequest with a WebException - "System.Net.WebException: The
server committed a protocol violation. Section=ResponseStatusLine".

Does anyone know of a workaround for this?

Thanks,
Colin

PS Code:
Code:

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

namespace ConsoleApplication1
{
public class InsertTest {
public static void Main() {

loHttp.Method = "POST";
byte[] lbPostBuffer = System.Text.

Encoding.GetEncoding(1252).GetBytes(lcPostData);
loHttp.ContentLength = lbPostBuffer.Length;

Stream loPostData = loHttp.GetRequestStream();
loPostData.Write(lbPostBuffer, 0, lbPostBuffer.Length);
loPostData.Close();
try
{
HttpWebResponse loWebResponse =
(HttpWebResponse)loHttp.GetResponse();
Encoding enc = System.Text.Encoding.GetEncoding(1252);

StreamReader loResponseStream =
new StreamReader(loWebResponse.GetResponseStream(), enc);

string lcHtml = loResponseStream.ReadToEnd();

loWebResponse.Close();
loResponseStream.Close();
}
catch (WebException J)
{
Console.WriteLine("Protocol violation!\n {0}", J.ToString());
}

string adj22 = Console.ReadLine();

}
}

}
Jul 21 '05 #1
1 1463
Whoops, sent wrong code in last message:
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Net;
using System.IO;
using System.Web;

namespace ConsoleApplication1
{
public class InsertTest {
public static void Main() {
string lcUrl = "http://patft.uspto.gov/netacgi/nph-Parser";
HttpWebRequest loHttp =
(HttpWebRequest)WebRequest.Create(lcUrl);

// *** Send any POST data
string lcPostData =
"Sect1=" + System.Web.HttpUtility.UrlEncode("PTO1") +
"&Sect2=" + System.Web.HttpUtility.UrlEncode("HITOFF") +
"&d=" + System.Web.HttpUtility.UrlEncode("PALL") +
"&p=" + System.Web.HttpUtility.UrlEncode("1") +
"&u=" +
System.Web.HttpUtility.UrlEncode("/netahtml/srchnum.htm") +
"&r=" + System.Web.HttpUtility.UrlEncode("1") +
"&f=" + System.Web.HttpUtility.UrlEncode("G") +
"&l=" + System.Web.HttpUtility.UrlEncode("50") +
"&s1=" + System.Web.HttpUtility.UrlEncode("6223224.WKU.") +
"&OS=" + System.Web.HttpUtility.UrlEncode("PN/6223224") +
"&RS=" + System.Web.HttpUtility.UrlEncode("PN/6223224");
loHttp.Method = "POST";
byte[] lbPostBuffer = System.Text.

Encoding.GetEncoding(1252).GetBytes(lcPostData);
loHttp.ContentLength = lbPostBuffer.Length;

Stream loPostData = loHttp.GetRequestStream();
loPostData.Write(lbPostBuffer, 0, lbPostBuffer.Length);
loPostData.Close();
try
{
HttpWebResponse loWebResponse =
(HttpWebResponse)loHttp.GetResponse();
Encoding enc = System.Text.Encoding.GetEncoding(1252);

StreamReader loResponseStream =
new StreamReader(loWebResponse.GetResponseStream(), enc);

string lcHtml = loResponseStream.ReadToEnd();

loWebResponse.Close();
loResponseStream.Close();
}
catch (WebException J)
{
Console.WriteLine("Protocol violation!\n {0}", J.ToString());

}
string adj22 = Console.ReadLine();

}
}
}
Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Lisa Pearlson | last post by:
Hi, I have a php script with no more than this: <?php echo "Hello World!"; ?> When a webbrowser client requests data, it receives Apache server headers, followed by my data: HTTP/1.1 200...
1
by: Fazer | last post by:
Hello, I have the following code: #!/usr/local/bin/python import cgi import Cookie C = Cookie.SimpleCookie() C = "f"
7
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. #...
7
by: Monty | last post by:
I've written a simple e-newsletter app using the PHP mail() command. I want to be able to deal with bounce-backs if a member's email is no longer working or is using an old account. I'm using a...
13
by: Eric Lilja | last post by:
Hello, consider the following complete program: #include <assert.h> #include <ctype.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <time.h> static int...
2
by: Colin Crossman | last post by:
So, I'm trying to write a web spider for some data gathering from a public database webserver. Anyway, in response to a POST, the webserver returns "200 Script Results Follow" instead of "201...
6
by: Sam | last post by:
I have some issues with HTTP Headers and I was hoping for some pointers or references to good articles. Here is the problem. I have 6 .aspx pages, each page contains a common .ascx. This ascx...
1
by: Ale News | last post by:
Hi to All.. I must add some custom headers HTTP and then i would to read them.. I used the AppendHeader Method to add my headers but when i try to read the headers i can't see my custom ones.....
42
by: yong | last post by:
Hi all I have an large integer in this format x1*256^5 + x2*256^4 + x3*256^3 + x4*256^2 + x5*256 + x6 now I must convert it to this format y1*900^4 + y2*900^3 + y3*900^2 + y4*900 + y5 x1-x5...
3
by: Rambaldi | last post by:
Since i am not use to program in c++, i got this question: I've been thinking in making a mp3 player in C#, the language i am more confortable dealing with, but instead of using librarys provided...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.