HTTP Form Post in C#

  • Thread starter Thread starter rh1200la
  • Start date Start date
R

rh1200la

Hi all...i'm trying to do a form post in my codebehind file using this
method:

public static string HttpPost(string URI, string Parameters)
{
System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
//req.Proxy = new System.Net.WebProxy(ProxyString, true);

req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";

byte [] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters);
req.ContentLength = bytes.Length;

System.IO.Stream os = req.GetRequestStream ();
os.Write (bytes, 0, bytes.Length);
os.Close ();

System.Net.WebResponse resp = req.GetResponse();
if (resp== null) return null;

System.IO.StreamReader sr = new
System.IO.StreamReader(resp.GetResponseStream());
return sr.ReadToEnd().Trim();;
}

For some reason it's not posting to the necessary page on my dev server
and production server.

I have commented out: //req.Proxy = new
System.Net.WebProxy(ProxyString, true);
Do I need to have a ProxyString value? My dev box is under normal
Win2k3 firewall and my production server has a more sophisticated
firewall.

Any ideas why this won't post? We had previous code that would do an
HTTP Get using the System.Net.WebClient.OpenRead and it worked fine.
Any ideas???

Thanks.
 
What do you see in the log files? Are you running IIS on dev and
production? If so, what version?

Your best bet is to turn on loggin on your web server. Thats where I
would start.

Hope this helps!

Sean
 
Back
Top