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
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