導航:首頁 > 編程語言 > javapost編碼

javapost編碼

發布時間:2025-04-26 11:12:53

1. java語言使用post方式調用webService方式

WebService可以有Get、Post、Soap、Document四種方式調用,以下Java通過post方式調用WebService代碼:

importjava.io.BufferedReader;
importjava.io.IOException;
importjava.io.InputStream;
importjava.io.InputStreamReader;
importjava.io.OutputStream;
importjava.io.OutputStreamWriter;
importjava.net.URL;
importjava.net.URLConnection;
importjava.net.URLEncoder;
importorg.apache.cxf.endpoint.Client;
importorg.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
/**
*功能描述:WebService調用
*
*/
publicclassClientTest{
/**
*功能描述:HTTP-POST
*
*/
publicStringpost(){
OutputStreamWriterout=null;
StringBuildersTotalString=newStringBuilder();
try{
URLurlTemp=newURL(
"http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/getSupportCity");
URLConnectionconnection=urlTemp.openConnection();
connection.setDoOutput(true);
out=newOutputStreamWriter(connection.getOutputStream(),"UTF-8");
StringBuffersb=newStringBuffer();
sb.append("byProvinceName=福建");
out.write(sb.toString());
out.flush();
StringsCurrentLine;
sCurrentLine="";
InputStreaml_urlStream;
l_urlStream=connection.getInputStream();//請求
BufferedReaderl_reader=newBufferedReader(newInputStreamReader(
l_urlStream));
while((sCurrentLine=l_reader.readLine())!=null){
sTotalString.append(sCurrentLine);
}
}catch(Exceptione){
e.printStackTrace();
}finally{
if(null!=out){
try{
out.close();
}catch(IOExceptione){
e.printStackTrace();
}
}
}
returnsTotalString.toString();
}
}
閱讀全文

與javapost編碼相關的資料

熱點內容
如何選擇php培訓機構 瀏覽:982
app被移除管理了怎麼弄 瀏覽:934
phpredis消息推送 瀏覽:803
剪貼板里怎麼加密碼 瀏覽:153
51單片機入門自學 瀏覽:548
如何看步數有同步伺服器 瀏覽:10
單片機掃描實驗代碼 瀏覽:721
惠州抖音app推廣平台怎麼引流 瀏覽:758
如何再網路設置裡面添加伺服器 瀏覽:191
陶瓷pdf 瀏覽:672
選股指標源碼最新 瀏覽:577
arm嵌入式linuxpdf 瀏覽:477
本田裂行的壓縮比 瀏覽:24
ps色彩調色命令 瀏覽:592
寬頻的伺服器地址怎麼看 瀏覽:423
vb如何給文件加密 瀏覽:215
python柱狀圖顯示前十 瀏覽:63
文件包加密是什麼意思 瀏覽:500
南方加密狗多少錢一隻 瀏覽:839
php100張恩民視頻 瀏覽:640