473,651 Members | 2,775 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();

}
}

}
Jul 21 '05 #1
1 1479
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();

}
}
}
Jul 21 '05 #2

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

Similar topics

10
3036
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
2220
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
9277
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
12444
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...
13
1843
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);
2
1610
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...
6
4316
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.
1
1692
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.. why this? i've read the headers with Request.Headers collection.. i can see only the default http headers.. can anyone help me?
42
3342
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
1496
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
8357
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8277
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,...
0
8803
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8581
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...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5612
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
4144
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...
1
1910
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1588
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.