Does anyone know a simple way to send an int
, a string
, or a byte[]
from a Windows Form Application via 'POST'
method and get this data in an ASP.NET WebForm?
So, in fact:
Form1 (data) -→ (data) WebPage1.aspx
Here is what I have now in my code : Client side :
String idtostring = "id=" + opid.ToString();
intarray = Encoding.ASCII.GetBytes(idtostring);
startlog(intarray);
private void startlog(byte[] array)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:51146/MyPage.aspx");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = array.Length;
var Url = "http://localhost:51146/MyPage.aspx";
wb.Navigate(Url, true);
Stream postdata = request.GetRequestStream();
postdata.Write(array, 0, array.Length);
postdata.Close();
}
Server side :
private String getpostdata()
{
return Request.Form["id"];
}
And this returns null... I don't know whether the problem is on client side or on server side. What I need to do is send from the client a data which looks like "id=7" via POST
method and get it back on the server. I'm using the id I get to custom authenticate an user so I need to show in the Web Browser the session where the user will be authenticated.
UPDATE : I'm not sure Request.Form is the right place to watch...
See this image which shows what I got with a breakpoint (I'm new so I cannot post images for the moment) → https://i.stack.imgur.com/3VTyL.png
I just tried with this :
private void startlog(byte[] array)
{
var Url = "http://localhost:51146/MyPage.aspx";
wb.Navigate(Url, "_blank", array, "");
}
And the result is exactly the same...