C# WebRequest GET/POST -


So I thought it's time for me to learn C #, to be easy with me, I am very new to this. / P>

I'm trying to create a very simple application (I'm using the Windows Forms app). My goal is:

  1. Use the "GET" method, get a web page
  2. Read the text field (this value is every time the user is reaching the page
  3. Using the "POST" method, send some values ​​accordingly

    This is my code yet:

      Private zero button 2_Click (Object Sender, EventArgs e) {string URI = "http: //localhost/post.php"; string myParameters = "field = value1 and field2 = value2"; (WebClient wc = new WebClient ()) Tax {string getpage = wc.DownloadString ("http: //localhost/post.php"); MessageBox.Show (getpage); Wc.Headers [HttpRequestHeader.ContentType] = "application / x-www-form-urlencoded"; String HtmlResult = wc.UploadString (URI, so far is pretty good, it is working but it is not entirely that I Here's what I want to achieve. I am able to use the post method, but how do I use GET before sending data? I want to send the data according to the GET result.  

    Please tell me I should give better

    thanks.

    Edit
    This is my PHP code:

        

    Now, back to my C # code, I get separate session ID in two messages

    Reading Data with GET

    Please refer to this answer:

     using  (web Client Client = New Web Client ()) {String s = client.DownloadString (url); }   

    session

    By default, webmail does not use any session. So every call is handled as if you have created a new session. To do this, you need something like this:

    Please refer to this answer:

  4. Example code: New CookieContainer (); Protected Override WebRequest GetWebRequest (URI address) {WebRequest request = base.GetWebRequest (address); HttpWebRequest webRequest = Request HttpWebRequest; If (webRequest! = Null) {webRequest.CookieContainer = m_container; } Refund Request; }} // ... Private Zero Button 2_Click (Object Sender, EventArgs E) {string URI = "http: //localhost/post.php"; String myParameters = "field = value1 and field2 = value2"; (WebClient wc = new CookieAwareWebClient ()) using {string getpage = wc.DownloadString ("http: //localhost/post.php"); MessageBox.Show (getpage); Wc.Headers [HttpRequestHeader.ContentType] = "app / x-www-form-urxed"; String HtmlResult = wc.UploadString (URI, myParameters); MessageBox.Show (HtmlResult); }}

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -