国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
java 實(shí)現(xiàn)天氣預(yù)報(bào) 用的是新浪的接口
  package com.lwz.wx.util;


import java.io.IOException;






import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;




import net.sf.json.JSONObject;


import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
 
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;




public class Gettqbycs {


public String palceRequestUrl(String city) throws UnsupportedEncodingException { 
  
//String url="http://xml.weather.yahoo.com/forecastrss?u=c&p=CHXX"+city;
String url="http://php.weather.sina.com.cn/xml.php?city="+city+"&password=DJOYnieT8234jlsK&day=0"; //這里的0 表示今天 要查明天換成 1
return url;
}


public String Gettqbycs(String csname) throws UnsupportedEncodingException{
String url = palceRequestUrl(csname); 
System.out.println(url);
String returnStr="";
HttpClient client = new HttpClient();
PostMethod getMethod = new PostMethod(url);
  
  try {
client.executeMethod(getMethod);
returnStr=new String(getMethod.getResponseBodyAsString().getBytes("iso-8859-1"),"UTF-8");//鏈接返回來(lái)的信息
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
  //JSONObject jsonObj = JSONObject.fromObject(returnStr );     
    String s=returnStr;
    // System.out.println(s);
     

return s;
};


public String readStringXml(String xml) {
StringBuffer buff=new StringBuffer();
        
         Document doc = null;
       try {
 
            // 讀取并解析XML文檔
             // SAXReader就是一個(gè)管道,用一個(gè)流的方式,把xml文件讀出來(lái)
            // 
             // SAXReader reader = new SAXReader(); //User.hbm.xml表示你要解析的xml文檔
           // Document document = reader.read(new File("User.hbm.xml"));
            // 下面的是通過(guò)解析xml字符串的
            doc = DocumentHelper.parseText(xml); // 將字符串轉(zhuǎn)為XML
 
            Element rootElt = doc.getRootElement(); // 獲取根節(jié)點(diǎn)
             System.out.println("根節(jié)點(diǎn):" + rootElt.getName()); // 拿到根節(jié)點(diǎn)的名稱
 
            Iterator iter = rootElt.elementIterator("Weather"); // 獲取根節(jié)點(diǎn)下的子節(jié)點(diǎn)Weather
 
             // 遍歷head節(jié)點(diǎn)
            while (iter.hasNext()) {
 
                 Element recordEle = (Element) iter.next();
                String city = recordEle.elementTextTrim("city"); // 拿到Weather節(jié)點(diǎn)下的子節(jié)點(diǎn)title值
                buff.append("您好,我是小V,以下是今天的天氣情況!").append("\n\n");  
                buff.append("城市:"+city).append("\n");
               
                String status1=recordEle.elementTextTrim("status1");
                
                String status2=recordEle.elementTextTrim("status2");
                buff.append("天氣情況:"+status1+"轉(zhuǎn)"+status2).append("\n");
                String temperature1=recordEle.elementTextTrim("temperature1");
                String temperature2=recordEle.elementTextTrim("temperature2");
                
                buff.append("溫度:"+temperature1+"~~"+temperature2+"攝氏度").append("\n");
                String chy_shuoming=recordEle.elementTextTrim("chy_shuoming");
                buff.append("建議穿衣:"+chy_shuoming).append("\n");
                
                String gm_s=recordEle.elementTextTrim("gm_s");
                buff.append("需要注意:"+gm_s).append("\n");
               
                buff.append("很高興為您服務(wù)").append("\n");
                buff.append("回復(fù) ? 顯示需要的幫助。").append("\n\n");;
                
            }

            
        } catch (DocumentException e) {
            e.printStackTrace();
 
         } catch (Exception e) {
           e.printStackTrace();
 
         }
         return  buff.toString();  
    }

   

public static void main(String[] args) {
Gettqbycs test=new Gettqbycs();
try {
String instr="福州天氣"; //這個(gè)是個(gè)人其他項(xiàng)目測(cè)試,可以自己處理下
System.out.println(instr.substring(2, 4));
String city=instr.substring(0, 2);
String ss= test.Gettqbycs(URLEncoder.encode(city, "GBK"));
String buffstr=test.readStringXml(ss);
System.out.println(buffstr);

 
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 
}


}     
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
dom4j解析xml字符串實(shí)例
JAVA版微信支付V3-完全版
使用HttpClient通過(guò)POST方式發(fā)送XML
通過(guò)HttpClient請(qǐng)求webService
利用HttpClient獲取網(wǎng)頁(yè)內(nèi)容
Java 使用httpclient Post與cxf 發(fā)布的Webservice通信
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服