HTTP Form Post in C#

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

Sean Chambers

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
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top