您的位置 首页 > 数码极客

javawebservice如何创建发布asmx文件

利用HttpURLConnection通过soap调用接口:

public static void cl6(String xml) throws IOException {

// 服务器地址

String urlString = ";;

// 需要调用的方法

String soapActionString = "getMobileCodeInfo";

URL url = new URL(urlString);

HttpURLConnection conn = (HttpURLConnection) url.openConnection();

// 拼接soap

String soap = xml;

byte[] buf = ("UTF-8");

// 设置报头

conn.setRequestProperty("Content-Length", S));

conn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");

conn.setRequestProperty("soapActionString", soapActionString);

conn.setRequestMethod("POST");

conn.setDoOutput(true);

conn.setDoInput(true);

OutputStream out = conn.getOutputStream();

out.write(buf);

out.close();

// 获取响应状态码

int code = conn.getResponseCode();

StringBuffer sb = new StringBuffer();

if (code == H()) {

InputStream is = conn.getInputStream();

byte[] b = new byte[1024];

int len = 0;

while ((len = is.read(b)) != -1) {

String s = new String(b, 0, len, "utf-8");

(s);

}

is.close();

}

Sy(sb);

}

public static void main(String args[]) throws IOException {

String str =

"<?xml version=/"1.0/" encoding=/"utf-8/"?>/n"

+ "/n"

+ "/n"

+ "/n"

+ "/n"

+ "/n"

+ "/n"

+ "/n"

+ "";

cl6(str);

}

使用HttpClient

public static void cl3() throws IOException {

// 输入服务网址

HttpClient client = new HttpClient();

// HttpClient client = new HttpClient(new HttpClientParams(), new SimpleHttpConnectionManager(true));

// GetMethod

PostMethod post = new PostMethod(";);

// 设置参数

("mobileCode", "");

("userID", "");

// client.setTimeout(newTimeoutInMilliseconds);

// 执行,返回一个结果码

int code = client.executeMethod(post);

Sy("结果码:" + code);

// 获取xml结果

String result = ();

Sy("结果:" + result);

// 释放连接

();

// 关闭连接

((SimpleHttpConnectionManager) client.getHttpConnectionManager()).shutdown();

}

使用jar

commons-httpclient

commons-httpclient

3.1

架构师视频资料分享链接:

data:text/html;charset=UTF-8;base64,

5p625p6E5biI5a2m5Lmg5Lqk5rWB576k5Y+35pivNjk2NTU1NTMyCg==

复制粘贴在网站即可!

共勉

责任编辑: 鲁达

1.内容基于多重复合算法人工智能语言模型创作,旨在以深度学习研究为目的传播信息知识,内容观点与本网站无关,反馈举报请
2.仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证;
3.本站属于非营利性站点无毒无广告,请读者放心使用!

“javawebservice如何创建发布asmx文件”边界阅读