连接对方接口得到格式xml数据

来源:互联网 发布:保健品网络推广怎么做 编辑:程序博客网 时间:2024/05/16 01:43

Constant.EMPLOEEINFO_WEBSERVICE_URL+ Constant.EMPLOEEINFO_BM;

配置的是两个常量,在系统宏里

public String webservicePort() {

String Str = null ;
try {
String strUrl = Constant.EMPLOEEINFO_WEBSERVICE_URL+ Constant.EMPLOEEINFO_BM;
System.out.println("URL:" + strUrl);
URL restURL = new URL(strUrl);
HttpURLConnection conn = (HttpURLConnection) restURL
.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setAllowUserInteraction(false);
PrintStream ps = new PrintStream(conn.getOutputStream());
ps.close();
BufferedReader bReader = new BufferedReader(new InputStreamReader(
conn.getInputStream(), "utf-8"));
String line;
StringBuffer resultStr = new StringBuffer();
int iLine = 0;
while ((line = bReader.readLine()) != null) {
resultStr.append(line + "\n");
iLine++;
}
System.out.println("resultStr:" + resultStr);
Str = resultStr.toString();
} catch (Exception e) {
System.out.print(e.getMessage());
}
return Str;
}
原创粉丝点击