本文整理自网络,侵删。
在您的使用中添加以下库:idSSLopenSSL,idHttp,Json这是POST JSON数据的示例代码:
procedure TForm1.Button1Click(Sender: TObject);var JsonStr: string; sResponse: string; JsonToSend: TStringStream; HTTP1: TidHTTP; F: TJSONObject;begin Button1.Enabled := False; memoResponse.Lines.Clear; memoRequest.Lines.Clear; F := TJSONObject.Create; F.AddPair('applicationId', edApplication.Text); F.AddPair('applicationPassword', edPassword.Text); F.AddPair('accountId', edAccount.Text); JsonStr := F.ToJSON; memoRequest.Text := JsonStr; JsonToSend := TStringStream.Create(JsonStr, TEncoding.UTF8); HTTP1 := TIdHTTP.Create(nil); try HTTP1.Request.ContentType := 'application/json; charset=utf-8'; HTTP1.Request.CharSet := 'utf-8'; try sResponse := HTTP1.Post(edURL.Text, JsonToSend); except on E: Exception do ShowMessage('Error on request: '#13#10 + e.Message); end; finally FreeAndNil(HTTP1); FreeAndNil(JsonToSend); FreeAndNil(F); end; memoResponse.Text := sResponse; Button1.Enabled := True;end;
您需要将OpenSSL DLL放在application.exe文件夹中:
libeay32.dllssleay32.dll
相关阅读 >>
Delphi getprocesshandleasname 获取进程句柄
Delphi xe5 android 调用 google zxing
Delphi使用tnethttpclient:重定向后如何给出最终的url?
更多相关阅读请进入《Delphi》频道 >>