- 论坛徽章:
- 0
|
webservice 的url ,在浏览器上输入url,需要用户名,密码才能打开xml
用java做客户端,怎么才能实现身份认证呢?服务端是.net做的,用xfire,axis都解决不了该怎么做?
北风网解答:
可以直接用HttpURLConnection来做客户端。- URL url = new URL("http://localhost/Incuity/ContentService.asmx");
- HttpURLConnection conn = (HttpURLConnection)url.openConnection();
- conn.setRequestMethod("POST");
- conn.setRequestProperty("content-type", "text/xml");\\根据具体情况定
- conn.setDoOutput(true);
- String passId = new String(Base64.encode("username:password".getBytes()));
- conn.setRequestProperty("Authorization", "Basic "+passId);
- conn.connect();
- OutputStream os = conn.getOutputStream();
复制代码 通过这个outputStream来发请求,像这样- String s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:bin=\"http://hello1/\">"
- + " <soapenv:Body> <bin:sayHello><arg0>morgan</arg0><arg1>23</arg1></bin:sayHello> </soapenv:Body></soapenv:Envelope>";
- os.write(s.getBytes());
复制代码 转自:http://bbs.ibeifeng.com/read-htm-tid-65883.html |
|