.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Getting post data

Posted By:      Posted Date: September 29, 2010    Points: 0   Category :ASP.Net

I am trying to get data posted to a site.  The only way i have been able to access these variable is through the headers:  

Posting script:

HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;

request.Headers["name"] = "Brandon";

Posted to script:


I have tried doing this but cannot access the variables in the Posted to Script..

            // Create the data we wnat to send
            string name = "Brandon";
            string api_key = "81834";

            StringBuilder data = new StringBuilder();
            data.Append("name=" + name);
            data.Append("lName=" + lName);

            // Create a byte array of the data we want to send
            byte[] byteData = System.Text.Encoding.ASCII.GetBytes(data.ToString());
// also tried the following:
// byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());
            // Set the content length in the request headers
            request.ContentLength =

View Complete Post

More Related Resource Links

server side does not save data when using POST data to another URL using WebRequest


 I am using a IIS 7.5 on Windows 7. I have a simple application that uses System.Net.WebRequest to POST data to another URL (in fact, the server side URL is on my local computer and it is hosted in IIS 7.5).

  1.  The problem is the server does not save data from client although on the client side codes when I debug and I see the OK message return from the code line

   response.StatusDescription; // this has value of "OK"
2. How can I debug the server code side where to receive the request from client side who posts the data ?

The following is the codes for client who posts data using System.Net.WebRequest, and codes for server side who received posted data to save to database.

Client side codes: // also run on my local computer

public string PostIntegrationXml(XmlDocument xmlSubmitDoc)




When I use 'publish', site doesn't work when i post data


Arrgghh, I am so tired of dealing with stuff like this

I've got a project, when I put up on another server I point two sites in IIS6 to it

i have

http://www.main.com  pointing to the folder the files are in


http://www.anotherofoursites.com/main pointing to that same folder in it's own "Virtual Application" or whatever IIS calls it when you put a folder into it's own 

If I just "Build" and push all the files up.. both work without issue and as expected...  but when I use "Publish" to precompile, the site works until I post, and then i get nailed with:

Server Error in '/' Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

How to post data to WCF REST without entity?

i just make a service like this:[WebHelp(Comment = "Login,Post Method")] [WebInvoke( Method="POST" ,UriTemplate = "Login?lName={loginName}&lPWD={password}&sID={sessionID}&domain={domain}")] [OperationContract] public ResultInfo Login(string loginName, string password,string sessionID,string domain) { return new ResultInfo() { Message = loginName, OptType = ResultType.FAILED  }; }and i call service like this:PostSubmitter post = new PostSubmitter(); post.Url = Constants.SSOCenterURL + "/Login"; post.PostItems.Add("lName", "kkdhf123456"); post.PostItems.Add("lPWD", "edU7qiWjrTzy764cZ7ahEg=="); post.PostItems.Add("sID", "rx543e12xc54235dhd23"); post.PostItems.Add("domain", "localhost"); post.Type = PostSubmitter.PostTypeEnum.Post; string result = post.Post();but service NOT get parametes . The 'loginName' will eques NULL.am i missing something? how to let WCF REST get the post data?thx your view.

Using HttpWebRequest to send POST data with parameters and a file

I have a form that has the following<form action="http://site" enctype="multipart/form-data" method="post"> <input type="hidden" name="action" value="the action" /> <input type="hidden" name="apiKey" value="key here" /> <input type="hidden" name="name" value="racing" /> <input type="hidden" name="title" value="Race Cars" /> <input type="hidden" name="signature" value="sig here" /> <input type="file" name="file" /> <input type="submit" name="_upload" value="Upload" /> </form>I know its not .net controls.. but hat doesn't matter for now, what I need to do is post this form with all it's data, but entirely in code.I have found this post: http://www.developmentnow.com/g/36_2005_3_0_0_300351/Using-HttpWebRequest-to-send-POST-data.htm this describes how to do it but I am not getting it.I will have a file upload on my page and a textbox for name and title, but the rest are generated in code.I know it's a long shot, but can anyone give me an example of exactly how I would do it for  my scenario? I have been at it all day and I am struggling! I keep getting bad gateway errors when

Programatically Send and receive data using Post Method

Hi,I wish to make a script which programatically send the POST data to one server and then the other server receive the POST message and retrieve the information. How should make this work? I already successfully write the sender site, the code as follow:string postData = "id=0&co=5";ASCIIEncoding encode = new ASCIIEncoding();         //data encoding         byte[] dataEncode = encode.GetBytes(postData);         //end ascii encoding scheme         string url = "http://localhost:51711/Handler1.ashx"; //         //web request         HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);         req.Method = "POST";         req.ContentType = "application/x-www-form-urlencoded";         req.ContentLength = dataEncode.Length;         //send data                Stream st = req.GetRequestStream();         st.Write(dataEncode, 0, dataEncode.Length);         st.Close();ASCIIEncoding encode = new ASCIIEncoding();byte[] dataEncode = encode.GetBytes(postData);stri

How to programmatically POST data to an aspx page?


Hi everyone,

I'm trying to POST data to an aspx page.

I've got a button click event (btnSend_Click) within which I want to programmatically POST data ("key1=value1", "key2=value2") to another aspx page ("ReceivingPage.aspx") on my site.  It would be very easy to do if it were a GET, cos I'd just append the data key/values to a query string of a HyperLink control. But How do I do this as a POST? 

Thanks for the help. 

Retain partial data in model over the post backs


Hello Everyone,

I have recently started learning ASP.NET with MVC 2 Framework, I am facing difficulties in the following scenarios

In my MVC application I want to retain partial information in Model over post backs.

Following is my scenario,

1.    I initiate "Edit" of main record by clicking date hyperlink from left navigation.
2.    Amend some data.
3.    Save the record.
4.    "Edit" sub record of the saved record by clicking another hyperlink from bottom left navigation panel.

The page is divided in to 6 tabs, the first 5 tabs shows the data for the main record and the 6th tab shows data of sub record.  Wehn we "Edit@ sub record the previous 5 tabs doesn't have any changes noted, that means there is no harm in keeping their details intact in the main model.  So is there a way to access model in the controller on hyper link click action so that I can only load the data for the clicked sub record (I am asking this, because the hyperlink click uses HTTP GET method so no model parameter passed in action method). If no, then how do I retain partial values in the Model over post backs?

Note that each tab data have been kept in individual models, and a main model has a collection member to hold all these individual models together.

C#/WPF: Constructing a HttpWebRequest to POST data not working


I am trying to POST data from a WPF app to the server, but it seems like I am doing it wrong. Server does not catch any GET/POST variables.


 req = HttpWebRequest.Create("http://jm/php/upload.php"
 boundary = "---------------------------"
 + DateTime.Now.Ticks;
 template = "\r\n\r\n"
 + boundary + "\r\n"
    "Content-Disposition: form-data; name=\"{0}\""
 + "\r\n\r\n"

req.Method = "POST"
req.ContentType = "multipart/form-data; boundary="
 + boundary;

 len = 0;
 reqStream = req.GetRequestStream())
 tmp = string
.Format(template, &qu

Post XML data to a URL


I have a Url like


Is there a way to post XML data to it.

Has anybody done something similar to point me the right direction to begin with.




Retrieving JavaScript data from a post



I'm using the WYSIWYG editor TinyEditor (http://www.leigeber.com/2010/02/javascript-wysiwyg-editor/), and I'm having an issue recalling the updated data. I searched the forum and found someone else had the same issue:


Thing is, I think I've done everything in the post, but my code is just not working. When I click submit, the variable in the code behind (val) isn't capturing any data - Object reference not set to an instance of an object.

Here's my code:

<%@ Page Title="" ValidateRequest="false" Language="C#" MasterPageFile="~/BackOffice.master" AutoEventWireup="true" CodeFile="about-us-club-officials.aspx.cs" Inherits="secure_page_content_about_us_club_officials" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Head" Runat="Server">
<asp:Content ID="Content2" Con

Post data to PHP


I have sample code for sending data from asp to PHP, but something goes wrong.

Here is the code


            StringBuilder postData = new StringBuilder();
            string url=""; 

              postData.Append("security=" + HttpUtility.UrlEncode(Md5AddSecret(txtGuid.Text)) + "&"); 
              postData.Append("auth=" + HttpUtility.UrlEncode("dsadasdsaads") + "&");
              postData.Append("action=" + HttpUtility.UrlEncode("new") + "&");
              postData.Append("username=" + HttpUtility.UrlEncode(txtUserName.Text) + "&");
              postData.Append("guid=" + HttpUtility.UrlEncode(txtG

Using the WebClient class to post data


Not sure if any of you are familiar with hMailServer, however, I am attempting to automate account creation / editing / deletion by using the WebClient class to interact with hMailServer's PHPWebAdmin.

The problem I am facing is that I can't seem to retrieve the index page (http://localhost/hmailserver/index.php) after posting the login credentials.

Here's my code so far....


string url = "http://localhost/hmailserver/";
var formData = new NameValueCollection();

formData["username"] = admin_user;
formData["password"] = admin_pass;

WebClient webClient = new WebClient();
byte[] responseBytes = webClient.UploadValues(url, "POST", formData);
string response = Encoding.UTF8.GetString(responseBytes);

And here's the HTML for the login form...


<form action="http://localhost/hmailserver/index.php" method="post" onSubmit="return formCheck(this);" name="mainform">
      <input type="hidden" name="page" value="background_login">
      <div align="center"&

How can i send a http post, to get the girdview's data ? thanks


how to send a http post to asp.net web,

and to get the gridiview's data .

Gridview like this:




Pls help to post the code to get data from sqldatasource into a list


I have this code but dunno how to get the data from the existing sqldatasource1 into the list. Pls help to post the code. 

ie the code for this line:        ' Get Data from Database and Fill DataReader and we will pass values to List

The sqldatasource1 returns only one field of data called holiday which is a date field. Thanks


<%@ Page Title="" Language="VB" MasterPageFile="~/00_MasterPage.master" %>

<script runat="server">

    Private Function GetPublicHolidays() As List(Of DateTime)

        Dim list As New List(Of DateTime)()

        ' Get Data from Database and Fill DataReader and we will pass values to List

    End Function


    <asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>

WCF UriTemplate and POST data


I am building a set of RESTful web services with WCF. I am trying to figure out how to combine the URITemplate with data being posted in the web call. 

This is the service contract section of one the methods I would like to expose:

[WebInvoke(Method = "POST", UriTemplate = "/{itemid}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
MyResponse doit(string itemid);

The URiTemplate resolver gives me the itemid parameter but how can I access the data being POSTed ?  


Using ASP to connect, post and get back data from MySQL DB



I'm a retired social worker creating some eLearning lessons and have a lesson that saves to a MS SQL Server DB, using ASP. I also have a component file in the lesson that can post/get back data but usually does this using PHP and a MySQL DB. The tutorial to help beginners like me provides PHP scripts compatible with the MySQL DB. But I need to post/get back data from a MS SQL Server DB and if possible use ASP for this.

I have the PHP scripts from the tutorial, and I've tested these with a sample MySQL DB. They work. What I need to do is "translate" the PHP into ASP so I can instead use a MS SQL Server DB which already is set up in the eLearning lesson.

I've seeached and searched, tried many sample scripts, connection strings. Nothing has worked.

I am posting the insert.php, select.php and delete.php scripts for a test project set up with a MySQL DB from the tutorial, in the hope that someone can suggest a way to "translate" these into working ASP versions that I can use with my MS SQL DB. I alos know that the connection string for the MS SQL Server DB uses OLE DB, but I already have this configuration from the eLearning lesson. (I don't know ehere to put it in an ASP script.)



$first = $HTTP_POST_VARS['first'];
$last = $HTTP_POST_VARS['last'];
$address = $HTTP_POST_VARS['address'];

Windows Azure service using arbitrary POST data


I need to spin up a Windows Azure service that accepts an HTTP POST with an arbitrary set of XML.  I have the service working fine with a specific XML signature, but now I'm trying to implement another method that will take any set of XML.  I've been searching for articles to help, and ran into a couple:



The first one shows the use of a attribute on the <binding> tag called contentTypeMapper.  The second shows how to implement that class, but adds the binding in code, not configuration.  I have been unsuccessful in creating my endpoint/binding/behavior in code, so I'm forced to do it in configuration.  So, I implemented my ContentTypeMapper class and added the attribute to my binding, but got a runtime error complaining about an unknown attribute contentTypeMapper.  I've checked the spelling and the case, and it is what it's supposed to be.  I'm guessing it's because I

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend