473,396 Members | 1,996 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,396 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 1466
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.