try Result :=IdHttp.Post(url,jsonToSend); except on e : Exception do begin ShowMessage(e.Message); end; end; finally jsonToSend.free; IdHttp.free; end;
end;
函数二:URL动态赋值,报错,无法使用。这里的url该如何定义? function PostDemo(url:string):string ; var IdHttp : TIdHTTP; IdSSLIOHandlerSocketOpenSSL: TIdSSLIOHandlerSocketOpenSSL; jsonToSend : TStringStream; begin IdHttp := TIdHTTP.Create(nil); IdSSLIOHandlerSocketOpenSSL := TIdSSLIOHandlerSocketOpenSSL.Create(nil); IdHttp.IOHandler := IdSSLIOHandlerSocketOpenSSL; IdHttp.HandleRedirects := True; IdHttp.Request.ContentType := 'application/json'; try
try Result :=IdHttp.Post(url,jsonToSend); except on e : Exception do begin ShowMessage(e.Message); end; end; finally jsonToSend.free; IdHttp.free; end;
end;
//调用报错 procedure TForm1.Button1Click(Sender: TObject); var url:string; begin url:='https://wai.xxxx.com/api/stock?id=3007&code=1548'+ '&m_data=[{"cine_code":"00323","stock":"14"},{"cine_code":"00711","stock":"25"}]'+ '×tamp=1611131907&sig=0289503c830be70c601f9666621984f6';