1 16 package dlog4j.blog; 17 18 import java.io.IOException ; 19 import java.net.URLEncoder ; 20 21 import org.apache.commons.httpclient.HttpClient; 22 import org.apache.commons.httpclient.methods.GetMethod; 23 import org.xml.sax.SAXException ; 24 25 30 public class BlogTrackBack { 31 32 43 public static TrackBackResp track(String refurl, 44 String log_url, 45 String blog_name, 46 String title, 47 String excerpt) throws IOException , SAXException { 48 HttpClient client = new HttpClient(); 49 StringBuffer sURL = new StringBuffer (refurl); 50 if(sURL.indexOf("?")==-1) 51 sURL.append('?'); 52 else 53 sURL.append('&'); 54 sURL.append("excerpt="); 55 sURL.append(URLEncoder.encode(excerpt,"UTF-8")); 56 sURL.append("&title="); 57 sURL.append(URLEncoder.encode(title,"UTF-8")); 58 sURL.append("&url="); 59 sURL.append(URLEncoder.encode(log_url,"UTF-8")); 60 sURL.append("&blog_name="); 61 sURL.append(URLEncoder.encode(blog_name,"UTF-8")); 62 GetMethod get = new GetMethod(sURL.toString()); 63 client.executeMethod(get); 64 try{ 65 return TrackBackResp.parse(get.getResponseBodyAsStream()); 66 }finally{ 67 get.releaseConnection(); 68 } 69 } 70 71 public static void main(String [] args) throws IOException , SAXException { 72 TrackBackResp resp = track("http://localhost:8080/dlog/trackback.do?log_id=458", 73 "http://www.javayou.com","Java自由人","测试标题","测试概要"); 74 System.out.println(resp); 75 } 76 } 77 | Popular Tags |