httpclient basic认证

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bowei026/article/details/51263482

1、httpclient basic认证的写法

post.setHeader("Authorization","Basic dXNlcjoxMjM0NTY=");

Authorization是写死的,Basic和空格也是死的,后面的R1c6Z3cyMDE2MDQwMTExMDY=是用户名和密码的Base64位加密


2、Base64位加密

加密的输入字符串是用户名:密码,如用户名是user,密码是123456,则需要加密的字符串是user:123456

算法:

String bstr = "GW:gw201604011106";
String encode = new sun.misc.BASE64Encoder().encode(bstr.getBytes());
System.out.println(encode);


也有提供在线加密的工具,如http://www1.tc711.com/tool/BASE64.htm,输入user:123456,点击编码按钮即可得到加密的文字,然后拼接成Basic dXNlcjoxMjM0NTY=即可

参考资料:http://www.tuicool.com/articles/vaAfuui


axis1.4调用webservice的basic认证:

System.setProperty ("jsse.enableSNIExtension", "false");
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress("https://xx.com.cn/Proxy_Services/OsbSSL_Demo?wsdl");
call.setOperationName("OsbSSL_DemoService");// WSDL里面描述的接口名称
call.setUsername("user");//http basic用户名
call.setPassword("123456");//http basic密码
call.addParameter("DATA", XMLType.XSD_STRING,
ParameterMode.IN);// 接口的参数
call.setReturnType(XMLType.XSD_STRING);//


String msg = (String) call.invoke(new Object[] {"测试" });
System.out.println(msg);

猜你喜欢

转载自blog.csdn.net/bowei026/article/details/51263482