当前位置:文库下载 > 所有分类 > IT/计算机 > 计算机软件及应用 > HttpClient示例
免费下载此文档侵权投诉

HttpClient示例

HttpClient示例

HttpClient示例

1 <%@page import="com.sun.xml.ws.client.BindingProviderProperties"%> 2 <%@page contentType="text/html;charset=UTF-8" language="java" %> 3 <%@page import="java.util.*"%>

4 <%@page import="java.io.*"%>

5 <%@page import="http://www.wenkuxiazai.commons.httpclient.*"%>

6 <%@page import="http://www.wenkuxiazai.commons.httpclient.methods.*"%>

7 <%

8 request.setCharacterEncoding("UTF-8");

9 String url = request.getParameter("url")==null?"":request.getParameter("url"); 10 String message = request.getParameter("message")==null?"":request.getParameter("message");

11 String result = "";

12

13 try {

14 //call service

15 if(url!=null && !"".equals(url)) {

16 PostMethod postMethod = new PostMethod(url);

17 byte[] bytes = message.getBytes("UTF-8");

18 InputStream inputStream = new ByteArrayInputStream(bytes, 0, 19 bytes.length);

20 RequestEntity requestEntity = new InputStreamRequestEntity(inputStream,

21 bytes.length, "application/soap+xml; charset=utf-8"); 22 postMethod.setRequestEntity(requestEntity);

23 //设置header

24 postMethod.setRequestHeader("OperationCode","com.mss.jt.cf.interfaces.SI_CF_YCHD_BALANCE_OUT_SynService");

25 postMethod.setRequestHeader("ClientId","com.mss.js.cf");

26 postMethod.setRequestHeader("TransactionId","B6B7B99D928B8581F92C4CBAEF3075F31508DB7F0BF856736A8AEBC25ADE69A0");

27 // 用户名密码:zpiappluser:zpiappl

28 postMethod.setRequestHeader("Authorization", " Basic "

29 + (new sun.misc.BASE64Encoder()).encode("zpiappluser:zpiappl"

30 .getBytes()));

31 HttpClient httpClient = new HttpClient();

32

33 int statusCode = httpClient.executeMethod(postMethod);

34 bytes = postMethod.getResponseBody();

35 result = new String(bytes,"UTF-8");

36 }

第1页

免费下载Word文档免费下载:HttpClient示例

(下载1-2页,共2页)

我要评论

返回顶部