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

熱點內容
php100張恩民視頻 瀏覽:640
安卓手機復制門禁卡加密 瀏覽:754
有哪些程序員特有的技能 瀏覽:399
痞幼資源包解壓密碼 瀏覽:699
pdf版本的ppt 瀏覽:176
網站伺服器地址在哪裡 瀏覽:715
python發行版常用包 瀏覽:212
nginx無法解析php 瀏覽:829
單片機編程基礎語言 瀏覽:308
私有雲伺服器怎麼設置 瀏覽:957
程序員的晚上生活 瀏覽:585
visualc的編譯鍵不見了 瀏覽:856
51單片機畢業設計論文 瀏覽:666
3doutline怎麼擴展命令 瀏覽:861
程序員生活費200 瀏覽:339
方舟編譯器與小米 瀏覽:184
佳明app訓練怎麼用 瀏覽:989
如何查看data有沒有加密 瀏覽:502
新福克斯壓縮比發動機 瀏覽:1000
斐波那契回調演算法公式 瀏覽:505