導航:首頁 > 編程語言 > 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編碼相關的資料

熱點內容
釘釘加密有用嗎 瀏覽:112
加密u盤好還是不加密的 瀏覽:349
微觀經濟學平狄克第八版pdf 瀏覽:403
linux查看實時流量 瀏覽:557
如何存檔到伺服器 瀏覽:548
flash編程書籍推薦 瀏覽:835
php獲得數組鍵值 瀏覽:401
香港雲伺服器操作 瀏覽:303
wpe最新源碼 瀏覽:857
自己購買雲主伺服器推薦 瀏覽:422
個人所得稅java 瀏覽:761
多餘的伺服器滑道還有什麼用 瀏覽:192
pdf劈開合並 瀏覽:29
不能修改的pdf 瀏覽:752
同城公眾源碼 瀏覽:489
一個伺服器2個埠怎麼映射 瀏覽:298
java字元串ascii碼 瀏覽:79
台灣雲伺服器怎麼租伺服器 瀏覽:475
旅遊手機網站源碼 瀏覽:332
android關聯表 瀏覽:946