Sidder nu og leger med det. Bruger følgende kode til at requeste:
WebRequest request = WebRequest.Create (@"
http://localhost/WebApplication5/WebForm1.aspx"); // Create a request using a URL that can receive a post.
request.Method = "POST"; // Set the Method property of the request to POST.
string postData = "username=thomas"; // Create POST data and convert it to a byte array.
byte[] byteArray = Encoding.UTF8.GetBytes (postData);
request.ContentType = "application/x-www-form-urlencoded"; // Set the ContentType property of the WebRequest.
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream (); // Get the request stream.
dataStream.Write (byteArray, 0, byteArray.Length); // Write the data to the request stream.
dataStream.Close (); // Close the Stream object.
WebResponse response = request.GetResponse (); // Get the response.
dataStream = response.GetResponseStream (); // Get the stream containing content returned by the server.
StreamReader reader = new StreamReader (dataStream); // Open the stream using a StreamReader for easy access.
string responseFromServer = reader.ReadToEnd (); // Read the content.
reader.Close (); // Clean up the streams.
dataStream.Close ();
response.Close ();
Og det her som test på en aspx side:
int loop1;
NameValueCollection coll;
//Load Form variables into NameValueCollection variable.
coll=Request.Form;
// Get names of all forms into a string array.
String[] arr1 = coll.AllKeys;
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
Response.Write("Form: " + arr1[loop1] + "<br>");
}
Syntes ikke det giver det ønsket resultat. Html der bliver returneret ser pænt underligt ud plus der ingen parametre er.