1

I need to write a forms application in C# that sends parameters via HTTP POST to a url, and gets back the response.

I really don't realize where to start this, is it possible at all ?

Thanks in advance, Gal.

2 Answers 2

7

As a start please see

1- HttpWebRequest Class

2- HttpWebResponse Class

3- WebClient Class

in MSDN

Please see Here

Sign up to request clarification or add additional context in comments.

Comments

4

This isn't in C# but you should be able to intepret it.

var
  Bytes: Array of Byte;
  Request: HttpWebRequest;
  RequestStream: Stream;
  Response: HttpWebResponse;
  ResponseStream: StreamReader;
begin  
    Bytes := Encoding.UTF8.GetBytes(Data); //Where data is your data (XML in my case)
    Request := WebRequest.CreateDefault(Uri.Create(URL)) as HttpWebRequest;
    Request.Method := 'POST';
    Request.ContentLength := Length(Bytes);
    Request.ContentType := 'application/xml'; //Set accordingly

    RequestStream := Request.GetRequestStream;
    RequestStream.Write(Bytes, 0, Length(Bytes));
    RequestStream.Close;

    Response := Request.GetResponse as HttpWebResponse;
    ResponseStream := StreamReader.Create(Response.GetResponseStream, Encoding.ASCII);
    Result := ResponseStream.ReadToEnd;
    ResponseStream.Close;

If you need clarification, let me know.

2 Comments

Seems like Delphi
@I'mBlueDaBaDee That it is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.