import java.io.ByteArrayInputStream;
import java.io.InputStream;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
public class Saml_Test {
private static final String soapRequestData =
" <SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+" <SOAP:Header>"
+" <wsse:Security xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">"
+" <wsse:UsernameToken xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">"
+" <wsse:Username>administrator</wsse:Username>"
+" <wsse:Password>cordys</wsse:Password>"
+" </wsse:UsernameToken>"
+" </wsse:Security>"
+" </SOAP:Header>"
+" <SOAP:Body>"
+" <samlp:Request xmlns:samlp=\"urn:oasis:names:tc:SAML:1.0:protocol\" MajorVersion=\"1\" MinorVersion=\"1\">"
+" <samlp:AuthenticationQuery>"
+" <saml:Subject xmlns:saml=\"urn:oasis:names:tc:SAML:1.0:assertion\">"
+" <saml:NameIdentifier Format=\"urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified\">administrator</saml:NameIdentifier>"
+" </saml:Subject>"
+" </samlp:AuthenticationQuery>"
+" </samlp:Request>"
+" </SOAP:Body>"
+"</SOAP:Envelope>";
public static void main(String[] args) {
try {
System.out.println(soapRequestData);
PostMethod postmethod = new PostMethod(
"http://10.200.1.128/cordys/com.eibus.web.soap.Gateway.wcp");
byte[] b = soapRequestData.getBytes("UTF-8");
InputStream is = new ByteArrayInputStream(b, 0, b.length);
RequestEntity re = new InputStreamRequestEntity(is, b.length,
"application/xop+xml; charset=UTF-8; type=\"text/xml\"");
postmethod.setRequestEntity(re);
HttpClient httpClient = new HttpClient();
int statusCode = httpClient.executeMethod(postmethod);
System.out.println("statuscode=" + statusCode);
String soapResponseData = postmethod.getResponseBodyAsString();
System.out.println(soapResponseData);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
分享到:
相关推荐
希望用http协议的能可以帮到大家!很有使用价值!大家可以看看!
java HttpClient 发送GET请求和带有表单参数的POST请求教程例子
HttpClient发送http请求(post+get)需要的jar包+内符java代码案例+注解详解
try(CloseableHttpClient httpClient = HttpClients.createDefault()) { HttpPost httpPost = new HttpPost(url); StringEntity stringEntity = new StringEntity(params, Charset.forName("UTF-8")); ...
HttpClient发送http请求(post+get)需要的jar包+内符java代码案例+注解详解(这款工具类是我精心挑选适合广大java程序猿使用)
其中包含项目post-demo定义接口;包含另一个项目httpclient-demo使用工具类发送post请求调用接口。详细内容查看博客 httpclient发送post请求
一个使用HttpClient访问WS 的例子,包含相关jar包
利用HttpClient发送HTTP请求 利用HttpClient发送HTTP请求
NULL 博文链接:https://daoshud1.iteye.com/blog/1847378
httpclient调用webservice.txt
本代码是httpclient发送get请求和post请求demo,具体描述参考博客 HttpClient发送get请求和post请求
主要介绍了java使用httpclient发送post请求示例,依赖JSON、HTTPClient等jar包,需要的朋友可以参考下
(完整版)JAVA利用HttpClient进行POST请求(HTTPS).doc
Java 编写的使用HttpClient发送http请求工具类(解决了session无法保留问题)
Ionic+Angular+Express实现前后端交互使用HttpClient发送get请求数据并加载显示示例代码
这个代码的意义在于展示了如何使用Java中的HttpClient库发送HTTP请求,并处理响应结果。在实际开发中,我们经常需要与Web服务进行交互,例如查询数据库、提交表单等。通过学习这个示例,你可以了解到如何使用...
不会的可以在评论区留言哈,这是我自己做项目用到的。所以绝对可用!同时共享出来给到大家
JAVA发送HttpClient请求及接收请求结果过程
httpclient发送post请求 txt中为代码,直接复制粘贴即可使用了