By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,458 Members | 1,201 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,458 IT Pros & Developers. It's quick & easy.

How to Post data to web app and reading response

P: n/a
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=P485W021&WHSE=3900&CUSTID=7901&PONBR=ES10 0&PART=LM24N&UPRICE=10&QTY=5";
HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(post_url);
httpRequest.Method = "POST";
httpRequest.ContentType = "application/x-www-form-urlencoded";

byte[] bytedata = Encoding.UTF8.GetBytes(poststring);
httpRequest.ContentLength = bytedata.Length;
Stream requestStream = httpRequest.GetRequestStream();
requestStream.Write(bytedata, 0, bytedata.Length);
requestStream.Close();

HttpWebResponse httpWebResponse = (HttpWebResponse)httpRequest.GetResponse();
Stream responseStream = httpWebResponse.GetResponseStream();
StringBuilder sb = new StringBuilder();
using (StreamReader reader = new StreamReader(responseStream,
System.Text.Encoding.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.WebException: The remote server returned an error: (501) Not
Implemented. at System.Net.HttpWebRequest.CheckFinalStatus() at
System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)

Can anyone please help?

Thanks,
Tammy
Nov 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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=P485W021&WHSE=3900&CUSTID=7901&PONBR=ES10 0&PART=LM24N&UPRICE=10&QTY=5";
HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(post_url);
httpRequest.Method = "POST";
httpRequest.ContentType = "application/x-www-form-urlencoded";

byte[] bytedata = Encoding.UTF8.GetBytes(poststring);
httpRequest.ContentLength = bytedata.Length;
Stream requestStream = httpRequest.GetRequestStream();
requestStream.Write(bytedata, 0, bytedata.Length);
requestStream.Close();

HttpWebResponse httpWebResponse = (HttpWebResponse)httpRequest.GetResponse();
Stream responseStream = httpWebResponse.GetResponseStream();
StringBuilder sb = new StringBuilder();
using (StreamReader reader = new StreamReader(responseStream,
System.Text.Encoding.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.WebException: The remote server returned an error: (501) Not
Implemented. at System.Net.HttpWebRequest.CheckFinalStatus() at
System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)

Can anyone please help?

Thanks,
Tammy

Nov 17 '05 #2

P: n/a
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.ProtocolViolationException: 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=P485W021&WHSE=3900&CUSTID=7901&PONBR=ES10 0&PART=LM24N&UPRICE=10&QTY=5";
HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(post_url);
httpRequest.Method = "POST";
httpRequest.ContentType = "application/x-www-form-urlencoded";

byte[] bytedata = Encoding.UTF8.GetBytes(poststring);
httpRequest.ContentLength = bytedata.Length;
Stream requestStream = httpRequest.GetRequestStream();
requestStream.Write(bytedata, 0, bytedata.Length);
requestStream.Close();

HttpWebResponse httpWebResponse = (HttpWebResponse)httpRequest.GetResponse();
Stream responseStream = httpWebResponse.GetResponseStream();
StringBuilder sb = new StringBuilder();
using (StreamReader reader = new StreamReader(responseStream,
System.Text.Encoding.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.WebException: The remote server returned an error: (501) Not
Implemented. at System.Net.HttpWebRequest.CheckFinalStatus() at
System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)

Can anyone please help?

Thanks,
Tammy

Nov 17 '05 #3

P: n/a
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.ProtocolViolationException: 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=P485W021&WHSE=3900&CUSTID=7901&PONBR=ES10 0&PART=LM24N&UPRICE=10&QTY=5";
HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(post_url);
httpRequest.Method = "POST";
httpRequest.ContentType = "application/x-www-form-urlencoded";

byte[] bytedata = Encoding.UTF8.GetBytes(poststring);
httpRequest.ContentLength = bytedata.Length;
Stream requestStream = httpRequest.GetRequestStream();
requestStream.Write(bytedata, 0, bytedata.Length);
requestStream.Close();

HttpWebResponse httpWebResponse = (HttpWebResponse)httpRequest.GetResponse();
Stream responseStream = httpWebResponse.GetResponseStream();
StringBuilder sb = new StringBuilder();
using (StreamReader reader = new StreamReader(responseStream,
System.Text.Encoding.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.WebException: The remote server returned an error: (501) Not
Implemented. at System.Net.HttpWebRequest.CheckFinalStatus() at
System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)

Can anyone please help?

Thanks,
Tammy

Nov 17 '05 #4

P: n/a
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.ProtocolViolationException: 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=P485W021&WHSE=3900&CUSTID=7901&PONBR=ES10 0&PART=LM24N&UPRICE=10&QTY=5";
> HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(post_url);
> httpRequest.Method = "POST";
> httpRequest.ContentType = "application/x-www-form-urlencoded";
>
> byte[] bytedata = Encoding.UTF8.GetBytes(poststring);
> httpRequest.ContentLength = bytedata.Length;
> Stream requestStream = httpRequest.GetRequestStream();
> requestStream.Write(bytedata, 0, bytedata.Length);
> requestStream.Close();
>
> HttpWebResponse httpWebResponse = (HttpWebResponse)httpRequest.GetResponse();
> Stream responseStream = httpWebResponse.GetResponseStream();
> StringBuilder sb = new StringBuilder();
> using (StreamReader reader = new StreamReader(responseStream,
> System.Text.Encoding.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.WebException: The remote server returned an error: (501) Not
> Implemented. at System.Net.HttpWebRequest.CheckFinalStatus() at
> System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)
>
> Can anyone please help?
>
> Thanks,
> Tammy

Nov 17 '05 #5

P: n/a
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.Create(post_url);
httpRequest = (HttpWebRequest)WebRequest.Create (post_url+"?"+poststring);

// Set credentials to use for this request.
httpRequest.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse)httpRequest.GetResponse ();

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

// 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.ReadToEnd ());
response.Close ();
readStream.Close ();
"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.ProtocolViolationException: 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=P485W021&WHSE=3900&CUSTID=7901&PONBR=ES10 0&PART=LM24N&UPRICE=10&QTY=5";
> > HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(post_url);
> > httpRequest.Method = "POST";
> > httpRequest.ContentType = "application/x-www-form-urlencoded";
> >
> > byte[] bytedata = Encoding.UTF8.GetBytes(poststring);
> > httpRequest.ContentLength = bytedata.Length;
> > Stream requestStream = httpRequest.GetRequestStream();
> > requestStream.Write(bytedata, 0, bytedata.Length);
> > requestStream.Close();
> >
> > HttpWebResponse httpWebResponse = (HttpWebResponse)httpRequest.GetResponse();
> > Stream responseStream = httpWebResponse.GetResponseStream();
> > StringBuilder sb = new StringBuilder();
> > using (StreamReader reader = new StreamReader(responseStream,
> > System.Text.Encoding.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.WebException: The remote server returned an error: (501) Not
> > Implemented. at System.Net.HttpWebRequest.CheckFinalStatus() at
> > System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)
> >
> > Can anyone please help?
> >
> > Thanks,
> > Tammy

Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.