進口?Java . io . buffered reader;
進口?Java . io . io exception;
進口?Java . io . inputstream;
進口?Java . io . inputstreamreader;
進口?Java . io . output stream;
進口?Java . io . output streamwriter;
進口?Java . net . URL;
進口?Java . net . URL connection;
進口?Java . net . URL encoder;
進口?org . Apache . cxf . endpoint . client;
進口?org . Apache . cxf . jaxws . endpoint . dynamic . jaxwsdynamicclientfactory;
/**
*?功能描述:WebService調用
*?
*/
公共?班級?ClientTest?{
/**
*?功能描述:HTTP-POST
*?
*/
公共?字符串?post()?{
OutputStreamWriter?出局?=?null
StringBuilder?sTotalString?=?新的?StringBuilder();
試試?{
網址?urlTemp?=?新的?網址(
"/web services/weather web service . asmx/getSupportCity ");
URLConnection?聯系?=?URL temp . open connection();
connection . setdoooutput(true);
出局?=?新的?output streamwriter(connection . get output stream(),?“UTF-8”);
StringBuffer?sb?=?新的?string buffer();
Sb.append("byProvinceName=福建");
out . write(sb . tostring());
out . flush();
字符串?sCurrentLine
sCurrentLine?=?"";
InputStream?l _ urlStream
l_urlStream?=?connection . getinputstream();//?請求
BufferedReader?l_reader?=?新的?BufferedReader(新?輸入流閱讀器(
l _ urlStream));
什麽時候?((sCurrentLine?=?l_reader.readLine())?!=?null)?{
stotalstring . append(sCurrentLine);
}
}?接住?(例外?e)?{
e . printstacktrace();
}?終於?{
如果?(null?!=?出)?{
試試?{
out . close();
}?接住?(IOException?e)?{
e . printstacktrace();
}
}
}
回歸?stotalstring . tostring();
}
}