Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

Programmatic HTTP Post returns Empty Form fields on ASPX Server Side

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ERobishaw - 22 Mar 2008 22:35 GMT
Using Winform app writing a HTTP Post using the following... on the
server side, I get no form fields.  Request.Form.AllKeys.Length = 0.

If I put the field/value paris in the URL I can use
Request["FieldName"] to retrieve the values,
but POST doesn't work.

There is NO Proxy... the only thing I can think is that ASP.NET is
somehow filtering out the page because I'm obviously not posting the
viewstate???  Seems like there was some setting for this, but I can't
recall what it is.

    HttpWebRequest request = (HttpWebRequest)
HttpWebRequest.Create("http://localhost/test.aspx");
    WebResponse response;

    string commentField = "ABCD=123";

    ASCIIEncoding encoding = new ASCIIEncoding();
    byte[] data = encoding.GetBytes(commentField);
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = data.Length;
    Stream stream = request.GetRequestStream();
    stream.Write(data, 0, data.Length);
    stream.Close();
    response = request.GetResponse();

//SERVER SIDE, test.aspx page
Page_Load()
{
    //BREAK POINT SET HERE>>>>
    //Request.Form.AllKeys returns nothing (0 length)
}
Anthony Jones - 22 Mar 2008 22:59 GMT
> Using Winform app writing a HTTP Post using the following... on the
> server side, I get no form fields.  Request.Form.AllKeys.Length = 0.
[quoted text clipped - 30 lines]
>      //Request.Form.AllKeys returns nothing (0 length)
> }

Viewstate won't impact this code.  The request object is a lower level
object provided by the HttpContext that is present in any handler be that an
ASPX or ASHX etc.

I can't explain why AllKeys has a length of 0, your calling code looks good.
Have you tried the System.Net.WebClient object instead.  It handles a lot of
this stuff for you:-

NameValueCollection fields = new NameValueCollection();
WebClient client = new WebClient();
fields.Add("ABCD", "123");
String response = client.UploadValues("http://localhost/test.aspx", fields);

Signature

Anthony Jones - MVP ASP/ASP.NET


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.