访问含有Basic认证的webservcie服务,生成client文件

在访问含有Basic认证的webservcie服务,浏览器会弹出窗口需要输入用户名和密码 ,输入后才可以看到webservcie服务,这种形式就是Basic认证。

访问到了服务,下一步就要生成客户端文件。

导出命令:

wsimport -s G:\wsdlTest -p com.test.client -Xauthfile G:\xauthfile.txt -keep 你要访问的web服务地址

命令解释:

-s   指定文件生成在本地的路径

-p  指定生成文件的包结构

-Xauthfile  访问含有Basic认证所需要 通过认证的文件

该txt文件的内容: http://用户名:密码@你要访问的web服务地址

-keep  生成java源文件

导出前提:

 本地提前建好文件的文件包括:

 -s   指定的文件夹

-p   不用建立

-Xauthfile   提前建好文件,并在文件内写上上述内容

win + r 调出命令窗口  输入导出命令即可生成本地文件。

java代码通过认证

import java.net.Authenticator;
import java.net.PasswordAuthentication;

public void pass(){
	//认证
	Authenticator.setDefault(new Authenticator()  {   
    	protected PasswordAuthentication getPasswordAuthentication() {   
    		return new PasswordAuthentication("用户名","密码".toCharArray());   
    	}
    });
}	

猜你喜欢

转载自blog.csdn.net/loveLifeLoveCoding/article/details/86495995