调用地址:http://10.115.232.116:8083/hmwsa/services/Mhs5service?wsdl 接口名称:save_zydj 用delphi7 的 idhttp 如何post
时间: 2023-08-05 22:03:58 浏览: 151
使用Delphi 7的IdHTTP组件发送POST请求可以按照以下步骤进行:
1. 导入所需的单元:
```delphi
uses
IdHTTP, IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL, IdGlobal;
```
2. 创建一个IdHTTP实例和一个SSL处理器:
```delphi
var
http: TIdHTTP;
ssl: TIdSSLIOHandlerSocketOpenSSL;
begin
http := TIdHTTP.Create(nil);
ssl := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
try
http.IOHandler := ssl;
```
3. 设置POST请求的请求头和URL:
```delphi
http.Request.ContentType := 'application/json';
url := 'http://10.115.232.116:8083/hmwsa/services/Mhs5service';
```
4. 构建JSON数据并将其存储在TStringStream中:
```delphi
jsonData := '{"p_blh": "病历号值", "p_grbh": "社会保障号码值", "p_kh": "卡号值", "p_xm": "姓名值", "p_xb": "性别值"}';
postData := TStringStream.Create(jsonData, TEncoding.UTF8);
```
5. 发送POST请求并获取响应:
```delphi
response := http.Post(url, postData);
```
6. 处理响应结果,例如将其显示在消息框中:
```delphi
ShowMessage(response);
```
7. 释放资源:
```delphi
finally
postData.Free;
ssl.Free;
http.Free;
end;
```
完整的示例代码如下:
```delphi
uses
IdHTTP, IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL, IdGlobal, SysUtils;
procedure PostData;
var
http: TIdHTTP;
ssl: TIdSSLIOHandlerSocketOpenSSL;
url: string;
jsonData: string;
postData: TStringStream;
response: string;
begin
http := TIdHTTP.Create(nil);
ssl := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
try
http.IOHandler := ssl;
http.Request.ContentType := 'application/json';
url := 'http://10.115.232.116:8083/hmwsa/services/Mhs5service';
jsonData := '{"p_blh": "病历号值", "p_grbh": "社会保障号码值", "p_kh": "卡号值", "p_xm": "姓名值", "p_xb": "性别值"}';
postData := TStringStream.Create(jsonData, TEncoding.UTF8);
response := http.Post(url, postData);
ShowMessage(response);
finally
postData.Free;
ssl.Free;
http.Free;
end;
end;
```
请将示例代码中的URL和JSON数据替换为实际的接口地址和参数值,并确保已正确引入相关的组件。
阅读全文