473,378 Members | 1,314 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,378 software developers and data experts.

PRB - HttpWebRequest does not work with CGI websites and/or RAW da

ATS
PRB - HttpWebRequest does not work with CGI websites and/or RAW data

Please help,

I'm trying to make a web deploying UserControl that gets RAW binary data
that is dynamically created from a CGI application webiste, and have the
UserControl write the data down to a file. I've used the code listed here
after to make this happen. If I plug in a URL to a non-CGI site, such as a
static HTML page, the UserControl successfully get the output from the
webbsite and writes output to file. But if I plug in a URL to my CGI app,
which returns the same HTML data (and in fact was used to create the same
aforementioned static HTML page), then I get an error on the
HttpWebRequest.GetResponseStream of "protocol violation".

I've seen many mentions of using an app.config file to "fix" this issue, but
once I changed the URL to point to a static HTML file I knew that the call to
GetResponseStream needs something to tell it to NOT analyze the output. And
being that this is a UserControl, I can not use an app.config file, as the
UserControl is dployed over the web.

Any ideas?

=============

1st of all, I expect the HttpWebRequest to NOT analyze the content of what
is being returned, and certainly NOT to throw an exception. I need for the
CGI app to get either an HTTP GET or POST with potential HTML posted data or
certainly a query string so that it can generate the dynamic data I need. For
which the CGI app then sends down the data, which potentially will be RAW
binary data.

=============== C# code...

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Reflection;

namespace MyNameSpace
{
public class MyUserControl : System.Windows.Forms.UserControl
{

private System.ComponentModel.Container components = null;
public string csKey;
public string csOptions;
public string LA;
public string ERR;
public string csTemp;

public MyUserControl()
{
InitializeComponent();
}

protected override void Dispose(bool bDisposing)
{
if (bDisposing)
{
if (components != null)
{
components.Dispose();
}
}

base.Dispose(bDisposing);
}

#region Component Designer generated code
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion

public string Run(string csKey, string csOptions)
{
try
{
LA = "Download the object";
string csTargetDirectory;
csTargetDirectory = Environment.GetFolderPath
(
System.Environment.SpecialFolder.CommonProgramFile s
);
csTargetDirectory += "\\MyProduct";

if (!System.IO.Directory.Exists(csTargetDirectory))
{
System.IO.Directory.CreateDirectory(csTargetDirect ory);
}

string csTargetFile = Environment.GetFolderPath
(
System.Environment.SpecialFolder.ProgramFiles
);
csTargetFile += "\\MyProduct\\Binary-Output.dat";

FileStream FileStream_Output = new FileStream(csTargetFile,
FileMode.Create);

HttpWebRequest HttpWebRequest_Temp;
HttpWebRequest_Temp = (HttpWebRequest) WebRequest.Create
(
"http://SomeCgiWebSite/SomeCgiApp.exe"
);

HttpWebRequest_Temp.Method = "GET";

HttpWebResponse HttpWebResponse_Temp;
HttpWebResponse_Temp = (HttpWebResponse)
HttpWebRequest_Temp.GetResponse();

System.IO.Stream Stream_Input;
Stream_Input = HttpWebResponse_Temp.GetResponseStream(); // ERROR -
Protocol Violation.

int iReadLen = 0;
byte[] zbyteTemp = new byte[32000];

for
(
iReadLen = Stream_Input.Read(zbyteTemp, 0, 32000);
iReadLen > 0;
iReadLen = Stream_Input.Read(zbyteTemp, 0, 32000)
)
{
FileStream_Output.Write(zbyteTemp, 0, iReadLen);
}

Stream_Input.Close();
FileStream_Output.Close();

return "RET=OK";
}
catch(Exception Exception_ERR)
{
ERR = Exception_ERR.Message;
return "RET=ERR LA=" + LA + " ERR=" + ERR;
}
}
}
}

==================== HTML file that runs the UserControl
<html>
<body>
<object
id=MyUserControl
classid="http://MyWebSite//MyUserControl.dll#MyNameSpace.MyUserControl"
style="display: inline;"
VIEWASTEXT

</object>
</body>
<script language=jscript>
var MyUserControl;
MyUserControl = document.getElementById("MyUserControl");
alert("objTest.Run = '" + MyUserControl.Run("Key", "Options") + "'...");
</script>
</html>

Nov 17 '05 #1
1 2793
ATS wrote:
PRB - HttpWebRequest does not work with CGI websites and/or RAW data

Please help,

I'm trying to make a web deploying UserControl that gets RAW binary
data that is dynamically created from a CGI application webiste, and
have the UserControl write the data down to a file. I've used the
code listed here after to make this happen. If I plug in a URL to a
non-CGI site, such as a static HTML page, the UserControl
successfully get the output from the webbsite and writes output to
file. But if I plug in a URL to my CGI app, which returns the same
HTML data (and in fact was used to create the same aforementioned
static HTML page), then I get an error on the
HttpWebRequest.GetResponseStream of "protocol violation".

I've seen many mentions of using an app.config file to "fix" this
issue, but once I changed the URL to point to a static HTML file I
knew that the call to GetResponseStream needs something to tell it to
NOT analyze the output. And being that this is a UserControl, I can
not use an app.config file, as the UserControl is dployed over the
web.

Any ideas?


Capture the HTTP traffic with a tool like Fiddler (www.fiddlertool.com)
and add all HTTP headers that your code currently does not set.

A popular mistake is forgetting to set the User-Agent header, which
many web apps use to determine what client software sent the request
(IE, Firefox, a web crawler etc.).

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

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

Similar topics

0
by: v_kravch | last post by:
Hi, I am sending a time-consuming HttpWebRequest asynchronously and would like to get the current progress. Obvious solution, it would seem, to set progress in a session variable and send the...
16
by: thomas peter | last post by:
I am building a precache engine... one that request over 100 pages on an remote server to cache them remotely... can i use the HttpWebRequest and WebResponse classes for this? or must i use the...
4
by: R Reyes | last post by:
I am trying to code a file uploader (for forum/email attachments) from the client computer to a remote web server via the PUT method (since POST is not allowed ). However, the upload works ONLY...
3
by: Jason | last post by:
I'm having a hard time getting a call to HttpWebRequest's GetRequestSteam to work. Each time I try to run it, I get the following error: The underlying connection was closed: Unable to...
0
by: Susan Van Houen | last post by:
Hi Everybody, I have a problem that is driving me crazy and I am hoping for some help here. I am building an application (vb.net, vs2003) that crawls selected websites. The application works...
3
by: Tony Hunter | last post by:
Hello, I am trying to automatically login to websites after I have used SSO to get the credentials. For my test, I am working with my Yahoo account. The code that I am using is code that many...
4
by: Logician | last post by:
I am running on my PC Windows Forms to collect data from websites, including images. I hit a problem with images and javascript, and I would appreciate any help. The current code fails with a...
1
by: sindhurasingeetham | last post by:
Hi, I'm new to coding in .NET. I am trying to do an asynchronous call in my code using httpwebrequest. This code works perfectly fine on one server, but does not work on another. The main flow...
15
by: Nightcrawler | last post by:
I am currently using the HttpWebRequest and HttpWebResponse to pull webpages down from a few urls. string url = "some url"; HttpWebRequest httpWebRequest =...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.