The function PostDemo: string;
Var
IdHttp: TIdHTTP;
IdSSLIOHandlerSocketOpenSSL: TIdSSLIOHandlerSocketOpenSSL;
Url: string;
JsonToSend: TStringStream;
The begin
IdHttp:=TIdHTTP. Create (nil);
IdSSLIOHandlerSocketOpenSSL:=TIdSSLIOHandlerSocketOpenSSL. Create (nil);
IdHttp. IOHandler:=IdSSLIOHandlerSocketOpenSSL;
IdHttp. HandleRedirects:=True;
IdHttp. Request. ContentType:='application/json;
Try
Url:='https://wai.xxxx.com/api/stock? Id=3007 & amp; Code=1548 +
''& amp; m_data=https://bbs.csdn.net/topics/[{" cine_code ":" 00323 ", "stock" : "14"}, {" cine_code ":" 00711 ", "stock" : "25"}] + '
'& amp; Timestamp=1611131907 & amp; Sig=0289503 c830be70c601f9666621984f6 ';
Try
Result:=IdHttp. Post (url, jsonToSend);
Except,
On e: the Exception do
The begin
ShowMessage (e.M essage);
end;
end;
The finally
JsonToSend. Free;
IdHttp. Free;
end;
end;
Dynamic assignment function 2: URL, an error, can't use, how to define URL here?
The function PostDemo (url: string) : string;
Var
IdHttp: TIdHTTP;
IdSSLIOHandlerSocketOpenSSL: TIdSSLIOHandlerSocketOpenSSL;
JsonToSend: TStringStream;
The 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: the Exception do
The begin
ShowMessage (e.M essage);
end;
end;
The finally
JsonToSend. Free;
IdHttp. Free;
end;
end;
//call error
Procedure TForm1. Button1Click (Sender: TObject);
Var
Url: string;
The begin
Url:='https://wai.xxxx.com/api/stock? Id=3007 & amp; Code=1548 +
''& amp; m_data=https://bbs.csdn.net/topics/[{" cine_code ":" 00323 ", "stock" : "14"}, {" cine_code ":" 00711 ", "stock" : "25"}] + '
'& amp; Timestamp=1611131907 & amp; Sig=0289503 c830be70c601f9666621984f6 ';
Memo1. Text:=PostDemo (url);
end;
CodePudding user response:
You didn't create this two functions in jsonToSend, certain is both an error and could not have been what you said the first report not the second,Call way to then again, the url is correct, the difference between the two is that only one is the function definition and assignment, the other is through the parameters by the assignment outside a function, and in the use of the function does not have the difference,
Also, the next question don't just say an error, you have to specifically what kind of wrong, what is the error, first of all to learn how to ask questions, how to describe the problem, others can better help you solve,