前言:
现时你们对“soapui post请求”大致比较关心,大家都需要分析一些“soapui post请求”的相关文章。那么小编也在网络上收集了一些有关“soapui post请求””的相关知识,希望朋友们能喜欢,兄弟们一起来学习一下吧!SOAP-UI
SoapUI是为Windows、Mac和Linux操作系统开发的免费程序。作为测试SOAP(简单对象访问协议)和REST(代表性状态传输)web协议的一种方法,SoapUI提供了执行许多不同测试所需的工具和功能。这些测试包括功能测试、负载测试、安全测试和模拟。作为一个开源程序,SoapUI是市场上第一个同类的API测试工具,并且在开发人员的帮助下已经形成了今天的产品。
地址:,
生成SOAP
SOAP请求报文:
POST HTTP/1.1Accept-Encoding: gzip,deflateContent-Type: text/xml;charset=UTF-8SOAPAction: ""Content-Length: 299Host: 192.168.3.50:9199Connection: Keep-AliveUser-Agent: Apache-HttpClient/4.5.5 (Java/17.0.2)<soapenv:Envelope xmlns:soapenv="; xmlns:ser=";> <soapenv:Header/> <soapenv:Body> <ser:userInfo> <!--Optional:--> <username>?</username> </ser:userInfo> </soapenv:Body></soapenv:Envelope>
SOAP响应报文
HTTP/1.1 200 Content-Type: text/xml;charset=UTF-8Content-Length: 208Date: Fri, 11 Mar 2022 11:00:04 GMTKeep-Alive: timeout=60Connection: keep-alive<soap:Envelope xmlns:soap=";> <soap:Body> <ns2:userInfoResponse xmlns:ns2=";> <String>?</String> </ns2:userInfoResponse> </soap:Body></soap:Envelope>HTTPClient调用WebService服务
pom.xml
<!-- HttpClient--><dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.13</version></dependency><dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpmime</artifactId> <version>4.5.13</version></dependency><dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpasyncclient</artifactId> <version>4.1</version></dependency>
客户端调用
package com.what21.demo.service;import org.apache.http.Header;import org.apache.http.HttpEntity;import org.apache.http.client.config.RequestConfig;import org.apache.http.client.methods.CloseableHttpResponse;import org.apache.http.client.methods.HttpPost;import org.apache.http.entity.ContentType;import org.apache.http.entity.StringEntity;import org.apache.http.impl.client.CloseableHttpClient;import org.apache.http.impl.client.HttpClients;import org.apache.http.message.BasicHeader;import org.apache.http.util.EntityUtils;import java.io.IOException;public class WebServiceClientDemo { /** * @param args * @return */ public static void main(String[] args) { String url = ";; String xml = "<soapenv:Envelope xmlns:soapenv=\"\" xmlns:ser=\"\">\n" + " <soapenv:Header/>\n" + " <soapenv:Body>\n" + " <ser:userInfo>\n" + " <!--Optional:-->\n" + " <username>?</username>\n" + " </ser:userInfo>\n" + " </soapenv:Body>\n" + "</soapenv:Envelope>"; String result = null; HttpEntity httpEntity = null; try { CloseableHttpClient httpClient = HttpClients.createDefault(); // 创建POST HttpPost httpPost = new HttpPost(url); httpPost.setConfig(getRequestConfig()); // 设置头参数 Header contentTypeHeader = new BasicHeader("Content-Type", "text/xml;charset=UTF-8"); httpPost.setHeader(contentTypeHeader); Header soapActionHeader = new BasicHeader("SOAPAction", ""); httpPost.setHeader(soapActionHeader); // 头设置报文和通讯格式 StringEntity stringEntity = new StringEntity(xml, ContentType.TEXT_XML); stringEntity.setContentEncoding("UTF-8"); httpPost.setEntity(stringEntity); // 执行 CloseableHttpResponse httpResponse = httpClient.execute(httpPost); httpEntity = httpResponse.getEntity(); result = EntityUtils.toString(httpEntity); } catch (IOException e) { e.printStackTrace(); } finally { try { EntityUtils.consume(httpEntity); } catch (IOException e) { // http请求释放资源异常 e.printStackTrace(); } } System.out.println(result); } /** * @return */ public static RequestConfig getRequestConfig() { RequestConfig requestConfig = RequestConfig.custom() .setSocketTimeout(180 * 1000) // 连接超时时间 .setConnectTimeout(180 * 1000) // 请求超时时间 .setConnectionRequestTimeout(180 * 1000) // 连接请求超时时间 .setRedirectsEnabled(true) // 重定向开关 .build(); return requestConfig; }}
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。
标签: #soapui post请求