paip.百度空間 JAVA程式發文總結
GP百度空間不支援用戶端,只好自己開發了。。
使用HTTPCLIENT,COOKIE超長,先把它儲存在檔案裡,然後讀取。。自動斷行,需要
REPLACE掉換行..不然報400錯..
發文-------------------
POST /pub/submit/createtext HTTP/1.1
樣本
http://hi.baidu.com/pub/submit/createtext?
title=title24&content=txt24&private=0&imgnum=0&bdstoken=3a6bd382df05333ef96
3838cfa28f0d7&qbid=&refer=http:%2F%2Fhi.baidu.com
%2Fhome&private1=0&qing_request_source=
返回JSON
{"errorNo" : "501","errorMsg" : "user not login","data": [ ]}
每次返回時會重設BDSP , BDSTAT 這兩個COOKIE值..需要注意,雖然不重設這兩個值也可以
發文,不過發的HTML全部被轉碼了。。顯示源碼出來了。。
------------------------------------發送內容的URL轉碼----------
因為是通過 application/x-www-form-urlencoded"); 發送,所以發送內容需要進行URL編碼..
但是其中的漢字必須是UTF-8編碼,在這裡,漢字不能URL編碼。。。與標準編碼不同的是,百度
空間對問號不進行轉碼..所以,根據漢字UTF8編碼,其它進行URL編碼,所以不能和
title=java.net. URLEncoder.encode這個,只能自己編寫轉碼方法了,只對特殊符號進行轉碼,
除問號外...。。。
//dsi shha baidu konjye
//ati 2012.7.14
public static String urlEncode(String content) {
if(content==null) return "";
String html = content;
html = html.replace( "%", "%25"); //"
html = html.replace( "+", "%2B");
html = html.replaceAll( " ", "%20");
html = html.replace( "/", "%2F"); //"
// html = html.replace( "?", "%3F"); //"ngaidaolei
yao url endcode ,baidu konjye d byao .
html = html.replace( "#", "%23"); //"
html = html.replace( "&", "%26"); //"
html = html.replace( "=", "%3D"); //"
return html;
}