Elya
7 years ago

0

i try a lot of times but dont succeed..
where am i did mistake?

using System;
using System.IO;
using System.Net;
using System.Text;

namespace Examples.System.Net
{
public class WebRequestPostExample
{
public static void Main()
{
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create(“https://www.hackthis.co.uk/levels/intermediate/2”);
// Set the Method property of the request to POST.
request.Method = “POST”;
// Create POST data and convert it to a byte array.
string postData = “”;
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Set the ContentType property of the WebRequest.
request.ContentType = “application/x-www-form-urlencoded”;
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
// Get the response.
WebResponse response = request.GetResponse();
// Display the status.
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
Console.WriteLine(responseFromServer);
// Clean up the streams.
reader.Close();
dataStream.Close();
response.Close();

    }  
}  

}

2replies
2voices
179views
700Mh4ck3r
7 years ago

0

You went far away bro! It’s not that dificult.
One hint,

How you do a POST method form in HTML?

Elya
7 years ago

0

thanks 700Mh4ck3r.
i got it… after hours of programming..:-(

You must be logged in to reply to this discussion. Login
1 of 3

This site only uses cookies that are essential for the functionality of this website. Cookies are not used for tracking or marketing purposes.

By using our site, you acknowledge that you have read and understand our Privacy Policy, and Terms of Service.

Dismiss