title: Delphi HTTP Post JSON
body: <p>I am sure I'm doing something wrong here. I've followed every example I can find on stackoverflow and still haven't gotten this to work in my environment. I'd love to update my controls and environment, but I'm currently locked in with what I have. </p>
  
  <p>I am using:</p>
  
  <ul>
  <li>Delphi 7</li>
  <li>Indy 10.0.52</li>
  <li>ulkJSON.pas v1.07</li>
  </ul>
  
  <p>I need to send this JSON to a URL:</p>
  
  <pre class="lang-json prettyprint-override"><code>"auth": {
      "applicationId": "appID",
      "applicationPassword": "pwd",
      "accountId": "acct",
      "userId": "dev"
  }
  </code></pre>
  
  <p>There isn't anything terribly crazy about this, but when I try to post my request I tend to get a message that the request was Closed Gracefully. CheckIsReadable in IDSocketHandle.pas has Handleallocated = false. I'm not sure what I've done wrong in configuring my IdHTTP, but it just won't work.</p>
  
  <p>I have tried examples from all these questions and several more, but none of these approaches seem to work for me:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/17897521/post-json-data-to-restful-datasnap-server-from-delphi-client">Post JSON data to RESTful datasnap server from delphi client</a></li>
  <li><a href="https://stackoverflow.com/questions/16086101/sending-a-json-encoded-object-using-indy-and-delphi">Sending a JSON encoded object using Indy and Delphi</a></li>
  <li><a href="https://stackoverflow.com/questions/12175952/delphi-tidhttp-post-json/12200237#12200237">Delphi TIdhttp Post JSON?</a></li>
  <li><a href="https://stackoverflow.com/questions/12175952/delphi-tidhttp-post-json">Delphi TIdhttp Post JSON?</a></li>
  <li><a href="https://stackoverflow.com/questions/301991/whats-the-simplest-way-to-call-http-post-url-using-delphi">What’s the simplest way to call Http POST url using Delphi?</a></li>
  </ul>
  
  <p>Any tips would be greatly appreciated.</p>
  
  <p>The current variant looks like this:</p>
  
  <pre><code>procedure Tformmaintestbed.btnJSONSendClick(Sender: TObject);
  var
    code: Integer;
    sResponse: string;
    JsonToSend: TStringStream;
  begin
    JsonToSend := TStringStream.Create(
      '{"auth": {"applicationId": "' + edApplication.text +
      '","applicationPassword": "' + edpassword.text +
      '","accountId": "' + edaccount.text +
      '","userId": "' + edUser.text +
      '"}}');
    try
      HTTP1.Request.ContentType := 'application/json';
      HTTP1.Request.ContentEncoding := 'utf-8';
  
      memoRequest.lines.clear;
      memoRequest.lines.add(JsonToSend);
  
      try
        sResponse := HTTP1.Post(cbAddress.text, JsonToSend);
      except
        on E: Exception do
          ShowMessage('Error on request: '#13#10 + e.Message);
      end;
  
      memoResponse.lines.clear;
      memoresponse.lines.add(sResponse);
    finally
      JsonToSend.Free();
    end;
  end;
  </code></pre>
  
  <p>The idHTTP component is current set like this:</p>
  
  <pre><code>object HTTP1: TIdHTTP
    IOHandler = IdSSLIOHandlerSocketOpenSSL1
    AuthRetries = 0
    AuthProxyRetries = 0
    AllowCookies = True
    HandleRedirects = True
    ProxyParams.BasicAuthentication = False
    ProxyParams.ProxyPort = 0
    Request.ContentEncoding = 'utf-8'
    Request.ContentLength = -1
    Request.ContentRangeEnd = 0
    Request.ContentRangeStart = 0
    Request.ContentRangeInstanceLength = 0
    Request.ContentType = 'application/json'
    Request.Accept = 'application/json'
    Request.BasicAuthentication = False
    Request.UserAgent = 'Mozilla/3.0 (compatible; Indy Library)'
    HTTPOptions = [hoForceEncodeParams]
    Left = 564
    Top = 120
  end
  </code></pre>