473,802 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Web Exception: The
server committed a protocol violation. Section=Respons eStatusLine".

Does anyone know of a workaround for this?

Thanks,
Colin

PS Code:
Code:

using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Text.Reg ularExpressions ;
using System.Net;
using System.IO;
using System.Web;

namespace ConsoleApplicat ion1
{
public class InsertTest {
public static void Main() {

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

Encoding.GetEnc oding(1252).Get Bytes(lcPostDat a);
loHttp.ContentL ength = lbPostBuffer.Le ngth;

Stream loPostData = loHttp.GetReque stStream();
loPostData.Writ e(lbPostBuffer, 0, lbPostBuffer.Le ngth);
loPostData.Clos e();
try
{
HttpWebResponse loWebResponse =
(HttpWebRespons e)loHttp.GetRes ponse();
Encoding enc = System.Text.Enc oding.GetEncodi ng(1252);

StreamReader loResponseStrea m =
new StreamReader(lo WebResponse.Get ResponseStream( ), enc);

string lcHtml = loResponseStrea m.ReadToEnd();

loWebResponse.C lose();
loResponseStrea m.Close();
}
catch (WebException J)
{
Console.WriteLi ne("Protocol violation!\n {0}", J.ToString());
}

string adj22 = Console.ReadLin e();

}
}

}
Nov 17 '05 #1
2 1615
Whoops, sent wrong code in last message:
using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Text.Reg ularExpressions ;
using System.Net;
using System.IO;
using System.Web;

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

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

Encoding.GetEnc oding(1252).Get Bytes(lcPostDat a);
loHttp.ContentL ength = lbPostBuffer.Le ngth;

Stream loPostData = loHttp.GetReque stStream();
loPostData.Writ e(lbPostBuffer, 0, lbPostBuffer.Le ngth);
loPostData.Clos e();
try
{
HttpWebResponse loWebResponse =
(HttpWebRespons e)loHttp.GetRes ponse();
Encoding enc = System.Text.Enc oding.GetEncodi ng(1252);

StreamReader loResponseStrea m =
new StreamReader(lo WebResponse.Get ResponseStream( ), enc);

string lcHtml = loResponseStrea m.ReadToEnd();

loWebResponse.C lose();
loResponseStrea m.Close();
}
catch (WebException J)
{
Console.WriteLi ne("Protocol violation!\n {0}", J.ToString());

}
string adj22 = Console.ReadLin e();

}
}
}
Nov 17 '05 #2
Colin Crossman wrote:
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".
A 201 should only be returned if a new resource was created on the
server-side. If that is the case but you get a 200 response instead,
it's a server-side error.

Do note that "200 Script Results Follow" is a perfectly legal HTTP
status line. The HTTP spec defines status codes, but only *recommends*
reason phrases. Accordingly, "Script Results Follow" is as good as "OK"
or "Aye aye, Sir".

While both IE and Firefox ignore the odd header, this
response kills my HttpWebRequest with a WebException -
"System.Net.Web Exception: The server committed a protocol violation.
Section=Respons eStatusLine".

Does anyone know of a workaround for this?


What .NET version are you using? I've tested this briefly in both 1.1
and 2.0 Beta 2, and both work with arbitrary reason phrases:

Cheers,
--
http://www.joergjooss.de
mailto:ne****** **@joergjooss.d e
Nov 17 '05 #3

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

Similar topics

10
3045
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 OK
1
2226
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
9292
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. # No warranty express or implied for the accuracy, fitness to purpose
7
12459
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 Red Hat Linux server with Sendmail and Apache. I've seen mention of using Procmail or filtering mail to a certain account through a PHP script, but, can't find detailed instructions on how this is done. Can anyone let me know or point me toward...
1
1486
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 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...
13
1862
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 has_char(const char *, const char);
6
4327
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 serves two purposes, 1. it contains a tab strip with response.redirects to navigate to the other pages; 2. I authenticate the user by check to see if a cookie exists, if it doesn't I redirect to a login screen.
42
3382
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 is given.I must get y1-y4 from it. How can I do this on my 32bit PC?
3
1504
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 by Visual Studio, i want to deal with a library that i can have full knownledge of its code. I started searching for mp3 projects made in c++ and i found one thats good enough for me. WMp3 C++ class for Windows My objective is to make a .dll of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10285
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10063
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9114
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.