There is no way the code you showed can produce a socket error (let alone error 14001, which is not even a socket error) since the code won't even compile!
The TIdHTTP.Post()
method does not have an overload that accepts a TlkJSONobject
as input. How could it? TlkJSONobject
comes from a completely different 3rd party library, it is not part of the RTL or Indy. The only things you can POST
with TIdHTTP
are:
TStrings
-derived types
TStream
-derived types, including Indy's TIdMultiPartFormDataStream
- a file specified by a
String
filename
In this case, you need to use a TStream
to post JSON stored in memory. It is your responsibility to save your TlkJSONobject
content to a suitable TStream
of your choosing. That is outside the scope of Indy. For instance, you can use TlkJSON.GenerateText()
to get the JSON into a String
and then POST
it using a TStringStream
.
On a side note, the URL you are passing to TIdHTTP.Post()
is malformed. The correct delimiter between a hostname and port number is a colon (:
), not a semicolon (;
).
With that said, try this:
jso := TlkJSONobject.Create;
jso.Add('InvoiceNumber', '');
jso.Add('POSID', '910441');
jso.add('USIN', ePOSNo.Text);
jso.add('DATETIME', eDate.Text);
IdHTTP1.Request.Accept := 'application/json';
IdHTTP1.Request.ContentType := 'application/json';
{ Call the Post method of TIdHTTP and read the result into TMemo }
PostData := TStringStream.Create(TlkJSON.GenerateText(jso), TEncoding.UTF8);
try
Memo1.Lines.Text := IdHTTP1.Post('http://localhost:8524/api/IMSFISCAL/GetInvoiceNumberByModel', PostData);
finally
PostData.Free;
end;