title: Post Data to ASP .NET page using Delphi and TIdHttp
body: <p>I have an Asp .net page like this simple one <a href="http://issamsoft.com/app2/page1.aspx" rel="nofollow noreferrer">http://issamsoft.com/app2/page1.aspx</a> 
  and I want to post to it some data and extract data from the response,
  by using TIdHttp. I tried to do that in Delphi2009 like this:</p>
  
  <pre><code>Procedure TForm1.Button1Click(Sender: TObject);
  Const
  VIEWSTATE = '/wEPDwUKMjA3NjE4MDczNmRkSxPt/LdmgqMd+hN+hkbiqIZuGUk=';
  EVENTVALIDATION = '/wEWAwL40NXEDALs0bLrBgKM54rGBtmtdOYy+U7IFq8B25bYT1d4o1iK';
  FORMPARAMS = 'TextBox1=Issam&amp;Button1=Button';
  URL = 'http://issamsoft.com/app2/page1.aspx';
  var
  http: TIdHttp;
  lstParams: TStringList;
  begin
   http := TIdHTTP.Create(self);
   lstParams := TStringList.Create;
   try
    lstParams.Add('__VIEWSTATE='+VIEWSTATE);
    lstParams.Add('__EVENTVALIDATION='+EVENTVALIDATION);
    lstParams.Add(FORMPARAMS);
    http.Request.ContentType := 'application/x-www-form-urlencoded';
    Memo1.Lines.Text := http.Post(url,lstParams);
   finally
    http.Free;
    lstParams.Free;
   end;
  
  end;
  </code></pre>
  
  <p>but TIdhttp always gives an error(HTTP/1.1 500 Internal Server Error.) 
  I read some comments in the idHttp unit talks about problems with http protocol v 1.1 like this one:</p>
  
  <blockquote>
    <p>Currently when issuing a POST, IdHTTP will automatically set the protocol to version 
    1.0 independently of the value it had initially,  This is because
    there are some servers that don't respect the RFC to the full extent. In
    particular, they don't respect sending/not sending the Expect: 100-Continue
    header. Until we find an optimum solution that does NOT break the RFC, we
    will restrict POSTS to version 1.0.</p>
  </blockquote>
  
  <p>is there something wrong with my code or it's TidHttp Bug? and if the problem is in 
  TIdHttp, is there any workaround? or is there other solution using Indy components?</p>
  
  <p>besides. I've made a solution in C# using WebClient and it works very good.</p>
  
  <pre><code>        private void button1_Click(object sender, EventArgs e)
      {
          WebClient myClient = new WebClient();
          string viewstate = HttpUtility.UrlEncodeUnicode(@"/wEPDwUKMjA3NjE4MDczNmRkSxPt/LdmgqMd+hN+hkbiqIZuGUk=");
          string eventvaildation = HttpUtility.UrlEncodeUnicode(@"/wEWAwL40NXEDALs0bLrBgKM54rGBtmtdOYy+U7IFq8B25bYT1d4o1iK");
          string postdata = "__VIEWSTATE=" + viewstate + "&amp;" + 
              "__EVENTVALIDATION=" + eventvaildation + "&amp;TextBox1=Issam&amp;Button1=Button";
          myClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
          byte[] responce = myClient.UploadData("http://issamsoft.com/app2/page1.aspx", Encoding.ASCII.GetBytes(postdata));
          txtResponse.Text = Encoding.ASCII.GetString(responce);
      } 
  </code></pre>
  
  <p>where i can find (good/trusted) class like WebClient in Delphi?  free preferred :)</p>
  
  <p>Edit:
  I hope mechanism of VIEWSTATE,EVENTVALIDATION is clear enough for you, they are hash values generated by server, and they may change(already changed), my orginal project has a piece of code just to extract the current VIEWSTATE,EVENTVALIDATION values, but I omit that part just to make my example simple and clear, so when you want to try the above code you must take VIEWSTATE,EVENTVALIDATION values from the current page source.</p>