Delphi采用THTTPReqResp处理websever服务用例
1、先定义这个传入体
const
SOAPSTR = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:good="http://goodwillcis.com">'+
' <soapenv:Header>'+
' <good:JiaheSecurity>'+
' <!--Optional:-->'+
' <good:UserName>?</good:UserName>'+
' <!--Optional:-->'+
' <good:Password>?</good:Password>'+
' <!--Optional:-->'+
' <good:Timestamp>?</good:Timestamp>'+
' <!--Optional:-->'+
' <good:FromSYS>?</good:FromSYS>'+
' <!--Optional:-->'+
' <good:IV>?</good:IV>'+
' </good:JiaheSecurity>'+
' </soapenv:Header>'+
' <soapenv:Body>'+
' <good:Send>'+
' <!--Optional:-->'+
' <good:Input><![CDATA[%s]]></good:Input>'+
' </good:Send>'+
' </soapenv:Body>'+
'</soapenv:Envelope>';
2、采用 THTTPReqResp处理
sUrl := 'MSH|^\&|RES|RES|JHIP|JHIP|'+sDateTime+'||PSP^RTR^PSP_RTR|JHIP'+sDateTime+'|P|2.4'+#13#10
+ 'NDS|1|20190611113551^ORM_O01|'+ApatientHISID+'^^^^^^'+sApatientType;
sUrl := Format(SOAPSTR, [sUrl]);
sUrl := UTF8Encode(sUrl);
CoInitializeEx(Nil, COINIT_MULTITHREADED);
strSend := TStringStream.Create(sUrl, TEncoding.UTF8);
try
HTTPReqResp1 := THTTPReqResp.Create(nil);
HTTPReqResp1.URL :=GetRequestInfoURL;
strStream := TStringStream.Create('', TEncoding.UTF8);
HTTPReqResp1.SoapAction := 'http://goodwillcis.com/JHIP.SOAP.Service.HL7V2SOAPService.Send';
HTTPReqResp1.Agent := 'Apache-HttpClient/4.1.1 (java 1.5)';
HTTPReqResp1.UseUTF8InHeader := True;
HTTPReqResp1.Execute(strSend, strStream);
sRe := strStream.DataString;
SysLog.AddInfo('TFrmMain.SendWXInfo sRe',sRe);
sSendResultHL7 :=copy(sRe,pos('<![CDATA[',sRe)+length('<![CDATA['),length(sRe));
sSendResultHL7 :=copy(sSendResultHL7,0,pos(']]>',sSendResultHL7)-1);
Result := ParseHL7Request(sSendResultHL7,ApatientType);
except
on e: Exception do
begin
syslog.AddError('操作异常:', e.Message);
end;
end;