473,769 Members | 3,923 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Post data to web app and reading response

Hi,

I have an aspx app which needs to post data to a form and read the response.
I am confused on whether I should be using the get_url using "POST" method or
the post_url using "GET" method.

string get_url = "http://scmvs4:9090/gtccinfo/H485W020.HTML"; --url contains
a form
string post_url = "http://scmvs4:9090/cgi-bin/gticglnk/P485VEGA"; --called
by get_Url upon submit
string poststring =
"PROGRAM=P485W0 21&WHSE=3900&CU STID=7901&PONBR =ES100&PART=LM2 4N&UPRICE=10&QT Y=5";
HttpWebRequest httpRequest = (HttpWebRequest )WebRequest.Cre ate(post_url);
httpRequest.Met hod = "POST";
httpRequest.Con tentType = "applicatio n/x-www-form-urlencoded";

byte[] bytedata = Encoding.UTF8.G etBytes(poststr ing);
httpRequest.Con tentLength = bytedata.Length ;
Stream requestStream = httpRequest.Get RequestStream() ;
requestStream.W rite(bytedata, 0, bytedata.Length );
requestStream.C lose();

HttpWebResponse httpWebResponse = (HttpWebRespons e)httpRequest.G etResponse();
Stream responseStream = httpWebResponse .GetResponseStr eam();
StringBuilder sb = new StringBuilder() ;
using (StreamReader reader = new StreamReader(re sponseStream,
System.Text.Enc oding.UTF8))
{
string line;
while ((line = reader.ReadLine ()) != null)
{
sb.Append(line) ;
}
}
Response.Write( sb.ToString());
When I use the get_Url using POST method, I get this error:
System.Net.WebE xception: The remote server returned an error: (501) Not
Implemented. at System.Net.Http WebRequest.Chec kFinalStatus() at
System.Net.Http WebRequest.EndG etResponse(IAsy ncResult asyncResult)

Can anyone please help?

Thanks,
Tammy
Nov 17 '05 #1
5 17390
Looks to me like you have your POSTing code ok, you just need to POST it to
the "post_url",
"http://scmvs4:9090/cgi-bin/gticglnk/P485VEGA";

It looks like the Get_Url provides the form, and submits it via POST to the
post_url.

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Tammy" wrote:
Hi,

I have an aspx app which needs to post data to a form and read the response.
I am confused on whether I should be using the get_url using "POST" method or
the post_url using "GET" method.

string get_url = "http://scmvs4:9090/gtccinfo/H485W020.HTML"; --url contains
a form
string post_url = "http://scmvs4:9090/cgi-bin/gticglnk/P485VEGA"; --called
by get_Url upon submit
string poststring =
"PROGRAM=P485W0 21&WHSE=3900&CU STID=7901&PONBR =ES100&PART=LM2 4N&UPRICE=10&QT Y=5";
HttpWebRequest httpRequest = (HttpWebRequest )WebRequest.Cre ate(post_url);
httpRequest.Met hod = "POST";
httpRequest.Con tentType = "applicatio n/x-www-form-urlencoded";

byte[] bytedata = Encoding.UTF8.G etBytes(poststr ing);
httpRequest.Con tentLength = bytedata.Length ;
Stream requestStream = httpRequest.Get RequestStream() ;
requestStream.W rite(bytedata, 0, bytedata.Length );
requestStream.C lose();

HttpWebResponse httpWebResponse = (HttpWebRespons e)httpRequest.G etResponse();
Stream responseStream = httpWebResponse .GetResponseStr eam();
StringBuilder sb = new StringBuilder() ;
using (StreamReader reader = new StreamReader(re sponseStream,
System.Text.Enc oding.UTF8))
{
string line;
while ((line = reader.ReadLine ()) != null)
{
sb.Append(line) ;
}
}
Response.Write( sb.ToString());
When I use the get_Url using POST method, I get this error:
System.Net.WebE xception: The remote server returned an error: (501) Not
Implemented. at System.Net.Http WebRequest.Chec kFinalStatus() at
System.Net.Http WebRequest.EndG etResponse(IAsy ncResult asyncResult)

Can anyone please help?

Thanks,
Tammy

Nov 17 '05 #2
Thanks for the reply. However, if I use the post_url and the POST method, I
get "PROGRAM NOT SPECIFIED" which means the post_url could not find my
parameters in the post string. Also, tried the GET with the post_url and I
get "System.Net.Pro tocolViolationE xception: Cannot send a content-body with
this verb-type". Any suggestions would be greatly appreciated.
-Tammy
"Peter Bromberg [C# MVP]" wrote:
Looks to me like you have your POSTing code ok, you just need to POST it to
the "post_url",
"http://scmvs4:9090/cgi-bin/gticglnk/P485VEGA";

It looks like the Get_Url provides the form, and submits it via POST to the
post_url.

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Tammy" wrote:
Hi,

I have an aspx app which needs to post data to a form and read the response.
I am confused on whether I should be using the get_url using "POST" method or
the post_url using "GET" method.

string get_url = "http://scmvs4:9090/gtccinfo/H485W020.HTML"; --url contains
a form
string post_url = "http://scmvs4:9090/cgi-bin/gticglnk/P485VEGA"; --called
by get_Url upon submit
string poststring =
"PROGRAM=P485W0 21&WHSE=3900&CU STID=7901&PONBR =ES100&PART=LM2 4N&UPRICE=10&QT Y=5";
HttpWebRequest httpRequest = (HttpWebRequest )WebRequest.Cre ate(post_url);
httpRequest.Met hod = "POST";
httpRequest.Con tentType = "applicatio n/x-www-form-urlencoded";

byte[] bytedata = Encoding.UTF8.G etBytes(poststr ing);
httpRequest.Con tentLength = bytedata.Length ;
Stream requestStream = httpRequest.Get RequestStream() ;
requestStream.W rite(bytedata, 0, bytedata.Length );
requestStream.C lose();

HttpWebResponse httpWebResponse = (HttpWebRespons e)httpRequest.G etResponse();
Stream responseStream = httpWebResponse .GetResponseStr eam();
StringBuilder sb = new StringBuilder() ;
using (StreamReader reader = new StreamReader(re sponseStream,
System.Text.Enc oding.UTF8))
{
string line;
while ((line = reader.ReadLine ()) != null)
{
sb.Append(line) ;
}
}
Response.Write( sb.ToString());
When I use the get_Url using POST method, I get this error:
System.Net.WebE xception: The remote server returned an error: (501) Not
Implemented. at System.Net.Http WebRequest.Chec kFinalStatus() at
System.Net.Http WebRequest.EndG etResponse(IAsy ncResult asyncResult)

Can anyone please help?

Thanks,
Tammy

Nov 17 '05 #3
If you found out that you need to use the GET Verb, then everything needs to
be on the querystring:

http://scmvs4:9090/cgi-bin/gticglnk/...PRICE=10&QTY=5
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Tammy" wrote:
Thanks for the reply. However, if I use the post_url and the POST method, I
get "PROGRAM NOT SPECIFIED" which means the post_url could not find my
parameters in the post string. Also, tried the GET with the post_url and I
get "System.Net.Pro tocolViolationE xception: Cannot send a content-body with
this verb-type". Any suggestions would be greatly appreciated.
-Tammy
"Peter Bromberg [C# MVP]" wrote:
Looks to me like you have your POSTing code ok, you just need to POST it to
the "post_url",
"http://scmvs4:9090/cgi-bin/gticglnk/P485VEGA";

It looks like the Get_Url provides the form, and submits it via POST to the
post_url.

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Tammy" wrote:
Hi,

I have an aspx app which needs to post data to a form and read the response.
I am confused on whether I should be using the get_url using "POST" method or
the post_url using "GET" method.

string get_url = "http://scmvs4:9090/gtccinfo/H485W020.HTML"; --url contains
a form
string post_url = "http://scmvs4:9090/cgi-bin/gticglnk/P485VEGA"; --called
by get_Url upon submit
string poststring =
"PROGRAM=P485W0 21&WHSE=3900&CU STID=7901&PONBR =ES100&PART=LM2 4N&UPRICE=10&QT Y=5";
HttpWebRequest httpRequest = (HttpWebRequest )WebRequest.Cre ate(post_url);
httpRequest.Met hod = "POST";
httpRequest.Con tentType = "applicatio n/x-www-form-urlencoded";

byte[] bytedata = Encoding.UTF8.G etBytes(poststr ing);
httpRequest.Con tentLength = bytedata.Length ;
Stream requestStream = httpRequest.Get RequestStream() ;
requestStream.W rite(bytedata, 0, bytedata.Length );
requestStream.C lose();

HttpWebResponse httpWebResponse = (HttpWebRespons e)httpRequest.G etResponse();
Stream responseStream = httpWebResponse .GetResponseStr eam();
StringBuilder sb = new StringBuilder() ;
using (StreamReader reader = new StreamReader(re sponseStream,
System.Text.Enc oding.UTF8))
{
string line;
while ((line = reader.ReadLine ()) != null)
{
sb.Append(line) ;
}
}
Response.Write( sb.ToString());
When I use the get_Url using POST method, I get this error:
System.Net.WebE xception: The remote server returned an error: (501) Not
Implemented. at System.Net.Http WebRequest.Chec kFinalStatus() at
System.Net.Http WebRequest.EndG etResponse(IAsy ncResult asyncResult)

Can anyone please help?

Thanks,
Tammy

Nov 17 '05 #4
No, sorry to confuse you. I do not think the GET is the correct method
because of the Violation error. If I try the url
http://scmvs4:9090/cgi-bin/gticglnk/P485VEGA in a browser, I get PROGRAM NOT
SPECIFIED error. THis is the same error as my application. So I think now
it is just a matter of getting my query string passed. I also tried putting
everything in the querystring for the POST, but same error. For some reason
, it does not recognize my query string.

"Peter Bromberg [C# MVP]" wrote:
If you found out that you need to use the GET Verb, then everything needs to
be on the querystring:

http://scmvs4:9090/cgi-bin/gticglnk/...PRICE=10&QTY=5
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Tammy" wrote:
Thanks for the reply. However, if I use the post_url and the POST method, I
get "PROGRAM NOT SPECIFIED" which means the post_url could not find my
parameters in the post string. Also, tried the GET with the post_url and I
get "System.Net.Pro tocolViolationE xception: Cannot send a content-body with
this verb-type". Any suggestions would be greatly appreciated.
-Tammy
"Peter Bromberg [C# MVP]" wrote:
Looks to me like you have your POSTing code ok, you just need to POST it to
the "post_url",
"http://scmvs4:9090/cgi-bin/gticglnk/P485VEGA";

It looks like the Get_Url provides the form, and submits it via POST to the
post_url.

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Tammy" wrote:

> Hi,
>
> I have an aspx app which needs to post data to a form and read the response.
> I am confused on whether I should be using the get_url using "POST" method or
> the post_url using "GET" method.
>
> string get_url = "http://scmvs4:9090/gtccinfo/H485W020.HTML"; --url contains
> a form
> string post_url = "http://scmvs4:9090/cgi-bin/gticglnk/P485VEGA"; --called
> by get_Url upon submit
> string poststring =
> "PROGRAM=P485W0 21&WHSE=3900&CU STID=7901&PONBR =ES100&PART=LM2 4N&UPRICE=10&QT Y=5";
> HttpWebRequest httpRequest = (HttpWebRequest )WebRequest.Cre ate(post_url);
> httpRequest.Met hod = "POST";
> httpRequest.Con tentType = "applicatio n/x-www-form-urlencoded";
>
> byte[] bytedata = Encoding.UTF8.G etBytes(poststr ing);
> httpRequest.Con tentLength = bytedata.Length ;
> Stream requestStream = httpRequest.Get RequestStream() ;
> requestStream.W rite(bytedata, 0, bytedata.Length );
> requestStream.C lose();
>
> HttpWebResponse httpWebResponse = (HttpWebRespons e)httpRequest.G etResponse();
> Stream responseStream = httpWebResponse .GetResponseStr eam();
> StringBuilder sb = new StringBuilder() ;
> using (StreamReader reader = new StreamReader(re sponseStream,
> System.Text.Enc oding.UTF8))
> {
> string line;
> while ((line = reader.ReadLine ()) != null)
> {
> sb.Append(line) ;
> }
> }
> Response.Write( sb.ToString());
>
>
> When I use the get_Url using POST method, I get this error:
> System.Net.WebE xception: The remote server returned an error: (501) Not
> Implemented. at System.Net.Http WebRequest.Chec kFinalStatus() at
> System.Net.Http WebRequest.EndG etResponse(IAsy ncResult asyncResult)
>
> Can anyone please help?
>
> Thanks,
> Tammy

Nov 17 '05 #5
Peter, thanks so much for taking the time to reply to me. I solved my
problem by doing the following (works perfectly!):

HttpWebRequest httpRequest = (HttpWebRequest )WebRequest.Cre ate(post_url);
httpRequest = (HttpWebRequest )WebRequest.Cre ate (post_url+"?"+p oststring);

// Set credentials to use for this request.
httpRequest.Cre dentials = CredentialCache .DefaultCredent ials;
HttpWebResponse response = (HttpWebRespons e)httpRequest.G etResponse ();

// Get the stream associated with the response.
Stream receiveStream = response.GetRes ponseStream ();

// Pipes the stream to a higher level stream reader with the required
encoding format.
StreamReader readStream = new StreamReader (receiveStream, Encoding.UTF8);

Response.Write ("Response stream received.");
Response.Write (readStream.Rea dToEnd ());
response.Close ();
readStream.Clos e ();
"Tammy" wrote:
No, sorry to confuse you. I do not think the GET is the correct method
because of the Violation error. If I try the url
http://scmvs4:9090/cgi-bin/gticglnk/P485VEGA in a browser, I get PROGRAM NOT
SPECIFIED error. THis is the same error as my application. So I think now
it is just a matter of getting my query string passed. I also tried putting
everything in the querystring for the POST, but same error. For some reason
, it does not recognize my query string.

"Peter Bromberg [C# MVP]" wrote:
If you found out that you need to use the GET Verb, then everything needs to
be on the querystring:

http://scmvs4:9090/cgi-bin/gticglnk/...PRICE=10&QTY=5
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Tammy" wrote:
Thanks for the reply. However, if I use the post_url and the POST method, I
get "PROGRAM NOT SPECIFIED" which means the post_url could not find my
parameters in the post string. Also, tried the GET with the post_url and I
get "System.Net.Pro tocolViolationE xception: Cannot send a content-body with
this verb-type". Any suggestions would be greatly appreciated.
-Tammy
"Peter Bromberg [C# MVP]" wrote:

> Looks to me like you have your POSTing code ok, you just need to POST it to
> the "post_url",
> "http://scmvs4:9090/cgi-bin/gticglnk/P485VEGA";
>
> It looks like the Get_Url provides the form, and submits it via POST to the
> post_url.
>
> Peter
> --
> Co-founder, Eggheadcafe.com developer portal:
> http://www.eggheadcafe.com
> UnBlog:
> http://petesbloggerama.blogspot.com
>
>
>
>
> "Tammy" wrote:
>
> > Hi,
> >
> > I have an aspx app which needs to post data to a form and read the response.
> > I am confused on whether I should be using the get_url using "POST" method or
> > the post_url using "GET" method.
> >
> > string get_url = "http://scmvs4:9090/gtccinfo/H485W020.HTML"; --url contains
> > a form
> > string post_url = "http://scmvs4:9090/cgi-bin/gticglnk/P485VEGA"; --called
> > by get_Url upon submit
> > string poststring =
> > "PROGRAM=P485W0 21&WHSE=3900&CU STID=7901&PONBR =ES100&PART=LM2 4N&UPRICE=10&QT Y=5";
> > HttpWebRequest httpRequest = (HttpWebRequest )WebRequest.Cre ate(post_url);
> > httpRequest.Met hod = "POST";
> > httpRequest.Con tentType = "applicatio n/x-www-form-urlencoded";
> >
> > byte[] bytedata = Encoding.UTF8.G etBytes(poststr ing);
> > httpRequest.Con tentLength = bytedata.Length ;
> > Stream requestStream = httpRequest.Get RequestStream() ;
> > requestStream.W rite(bytedata, 0, bytedata.Length );
> > requestStream.C lose();
> >
> > HttpWebResponse httpWebResponse = (HttpWebRespons e)httpRequest.G etResponse();
> > Stream responseStream = httpWebResponse .GetResponseStr eam();
> > StringBuilder sb = new StringBuilder() ;
> > using (StreamReader reader = new StreamReader(re sponseStream,
> > System.Text.Enc oding.UTF8))
> > {
> > string line;
> > while ((line = reader.ReadLine ()) != null)
> > {
> > sb.Append(line) ;
> > }
> > }
> > Response.Write( sb.ToString());
> >
> >
> > When I use the get_Url using POST method, I get this error:
> > System.Net.WebE xception: The remote server returned an error: (501) Not
> > Implemented. at System.Net.Http WebRequest.Chec kFinalStatus() at
> > System.Net.Http WebRequest.EndG etResponse(IAsy ncResult asyncResult)
> >
> > Can anyone please help?
> >
> > Thanks,
> > Tammy

Nov 17 '05 #6

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

Similar topics

2
3277
by: Keith Selbee | last post by:
I am trying to submit data to a webpage in the form of a post and my code is below. It is a function that takes a url and the post content as strings and then performs the post. But as soon as I add the post data to the headers I get an exception that just says "headers". Can anyone please help me here? Thanks.... public string Get(string u, string c) { WebRequest wr = WebRequest.Create(u); wr.Headers.Add(c);
12
2673
by: Assaf | last post by:
Hi all, My client is using an online service provider that processes survey responses. After a user fills survey.aspx and presses the OK button, 2 things need to happen: 1. the data has to be posted behind the scenes to the provider's URL (e.g., http://www.surveyprocessingprovider.com/srvy1?field1=response1&field2=response2) 2. the user has to be redirected to thankyou.aspx.
4
2903
by: Piotr Strycharz | last post by:
Hi all I do have a problem. How can I transfer user to another server using POST. The problem is that Server.Transfer (preserves form data) works just in current server. Response.Redirect - uses GET method. However I have to open remote server page using POST method. Normally this can be achieved using <form ACTION="remote-page-url"> tag. However this is impossible with ASP.NET. Also, using WebRequest class is not good solution, as I...
5
3029
by: Vishal | last post by:
Hello, I already asked this question in the ASP.NET forums, but no help came. So I am hoping that somebody can help me out. This is really very URGENT me. For my e-commerce application, I need to send data from my server via the post method to the payment server. The payment server does not run asp.net. I dont know what they run. The payment server then returns to my server with the
10
3440
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a database or continue to process on to the next page. I am now trying to learn ASP to see if we can replace some of our applications that were written in php with an ASP alternative. However, after doing many searches on google and reading a couple...
0
1341
by: bertkuiken | last post by:
I'm new to .net and c# but have done this before at j2ee and php. All i want is to post a xml file as a string from an external website and retrieve it from the postdata at my c# programming code. Most of the examples online describe the posting of data at an external website, without the code for the external website or examples where the data was posted from an asp page to an asp page. This is the code I used, but reading out of the...
1
1482
by: gtg489w | last post by:
I'm having trouble reading data that i send to the server using ajax. The call I'm making in the client-side javascript is: fullProject.open("POST", url, false); fullProject.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); fullProject.send('var1=' + projectData); and I want to know how to grab that data using asp. The call that I've been manipulating is
1
2236
by: JohnathanKong | last post by:
Hello, I hope this is the right place to post, but anyways, here goes. I current have a forum, snitz, in place, but am having an IE specific problem. Basically what happens is, I have a page that drops a cookie which logs in the user. This all works fine, but once the cookie is dropped ALL post method data from forms become empty. Get works, and if I post data to a different site it works, so the break down is reading the data from the post....
0
9589
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
9423
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
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
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
9865
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
8873
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
6675
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
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.