Home > Back-end >  How can consult, Delphi through HTTP access, the request data from the server, and submit the data.
How can consult, Delphi through HTTP access, the request data from the server, and submit the data.

Time:12-08

Interfaces are accessed through HTTP, the request data from the server, and submit data,

Send a message interface

Access the address: Http://ceshi.com
Access category POST
Parameters of the title: the title of the message
Description: send information details

Example: Http://ceshi.com
Parameters as follows: {
Title: "your application has been approved,"
Description: "you to apply for the membership, has been to relevant departments for approval by"
}
Results for the JSON format {" code ": 0}

Excuse me this how to realized in Delphi, strives for the source code!

CodePudding user response:

IdHttp not line?

CodePudding user response:

I have enclosed a HTTP post and get, can use directly, parameters is the key value structure

The class function TSMSystem. GetResponseContent (const HTTP: TIdHTTP; Url: string;
Encode: TEncoding=nil; Param: TStrings=nil) : string;
Var
Response: TStringStream;
The begin
Result:=';
If the encode=nil then response:=TStringStream. Create (' ')
The else response:=TStringStream. Create (' ', encode);
Try
If param=nil then
The begin
The HTTP Get (url, response);
End
The else begin
HTTP Post (url, param, response);
end;
Result:=response. DataString;
Except,
end;
The response. Free;
end;

The key value, use the

The class function TSMSystem. GetResponseContentEx (const HTTP: TIdHTTP; Url: string;
Encode: TEncoding=nil; Param: TStringStream=nil) : string;
Var
Response: TStringStream;
The begin
Result:=';
If the encode=nil then
Response:=TStringStream. Create (')
The else
Response:=TStringStream. Create (' ', encode);

Try
If param=nil then
The begin
The HTTP Get (url, response);
End
The else begin
HTTP Post (url, param, response);
end;
Result:=response. DataString;
Except,
end;
The response. Free;
end;
  • Related