How to Post data to web app and reading response

G

Guest

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=ES100&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(IAsyncResult asyncResult)

Can anyone please help?

Thanks,
Tammy
 
G

Guest

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 said:
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 said:
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=ES100&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(IAsyncResult asyncResult)

Can anyone please help?

Thanks,
Tammy
 
G

Guest

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...D=7901&PONBR=ES100&PART=LM24N&UPRICE=10&QTY=5


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




Tammy said:
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 said:
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 said:
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=ES100&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(IAsyncResult asyncResult)

Can anyone please help?

Thanks,
Tammy
 
G

Guest

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 said:
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...D=7901&PONBR=ES100&PART=LM24N&UPRICE=10&QTY=5


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




Tammy said:
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 said:
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




:

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=ES100&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(IAsyncResult asyncResult)

Can anyone please help?

Thanks,
Tammy
 
G

Guest

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 said:
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 said:
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...D=7901&PONBR=ES100&PART=LM24N&UPRICE=10&QTY=5


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




Tammy said:
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


:

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




:

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=ES100&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(IAsyncResult asyncResult)

Can anyone please help?

Thanks,
Tammy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top