<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 1, 文章 - 44, 評論 - 2, 引用 - 0
    數據加載中……

    使用HttpURLConnection將字符流發送到servlet

    使用HttpURLConnection將字符流發送到servlet.
    此功能將字符串以流的形式發送給一個servlet.

    代碼如下:

    public String postStringToUrl(String Str, String urlStr){
    ??? ??? BufferedWriter bWriter = null;
    ??? ??? HttpURLConnection urlConn = null;
    ??? ??? String message = Str;
    ??? ??? String target = urlStr;
    ??? ??? String sCurrentLine = "";
    ??? ??? String sTotalString = "";
    ??? ??? int res = 0;
    ??? ??? try{
    ??? ??? ??? byte[] byteBuffer = message.getBytes("GB2312");
    ??? ??? ??? URL httpurl = new URL(target);
    ??? ??? ??? urlConn = (HttpURLConnection)httpurl.openConnection();
    ??? ??? ??? urlConn.setRequestProperty("Content-Type","application/octet-stream");
    ??? ??? ??? urlConn.setRequestProperty("Content-length", ""??? + byteBuffer.length);
    ??? ??? ??? urlConn.setRequestProperty("pure-data", "yes");
    ??? ??? ??? urlConn.setRequestProperty("Connection","Keep-Alive");
    ??? ??? ???
    ??? ??? ??? urlConn.setDoOutput(true);
    ??? ??? ??? OutputStream out = urlConn.getOutputStream();
    ??? ??? ???
    ??? ??? ??? try{
    ??? ??? ??? ??? out.write(byteBuffer);
    ??? ??? ??? }
    ??? ??? ??? finally{
    ??? ??? ??? ??? out.flush();
    ??? ??? ??? ??? out.close();
    ??? ??? ??? ??? message = null;
    ??? ??? ??? ??? target = null;
    ??? ??? ??? }
    ???
    ??? ?? ?? ? //url請求返回code值
    ??? ??? ??? res = urlConn.getResponseCode();
    ??? ??? ??? if (res == 200) {
    ??? ??? ??? ??? java.io.InputStream is = urlConn.getInputStream();
    ??? ??? ??? ??? BufferedReader reader = new BufferedReader(
    ??? ??? ??? ??? ??? ??? new InputStreamReader(is));
    ??? ??? ??? ??? while ((sCurrentLine = reader.readLine()) != null)
    ??? ??? ??? ??? ??? if (sCurrentLine.length() > 0)
    ??? ??? ??? ??? ??? ??? sTotalString = sTotalString + sCurrentLine.trim();
    ??? ??? ??? ??? String tmpStr = new String(sTotalString.getBytes("GB2312"));
    ??? ??? ??? ??? sTotalString = tmpStr;
    ??? ??? ??? } else {
    ??? ??? ??? ??? sTotalString = "遠程服務器連接失敗,錯誤代碼:"+res;

    ??? ??? ??? }

    ??? ??? ??? if (bWriter != null)
    ??? ??? ??? ??? bWriter.close();
    ??? ??? ??? ???
    ??? ??? }
    ??? ??? catch(Exception e){
    ??? ??? ??? sTotalString = "連接服務器失敗.";
    ??? ??? ??? e.printStackTrace();
    ??? ??? }
    ??? ??? return sTotalString;
    ??? }

    posted on 2006-06-06 13:41 ASONG 閱讀(419) 評論(0)  編輯  收藏 所屬分類: JAVA

    主站蜘蛛池模板: 日本免费高清视频| 国精产品一区一区三区免费视频| 亚洲第一网站免费视频| 亚洲AV无码成人精品区天堂| 国产真人无码作爱免费视频 | 永久黄网站色视频免费观看| 亚洲一区二区三区四区视频 | 怡红院亚洲怡红院首页| 国产高潮久久免费观看| 亚洲精品少妇30p| 97在线视频免费公开观看| 久久精品亚洲一区二区三区浴池| 亚洲免费黄色网址| 亚洲乱码国产乱码精华| 日韩精品成人亚洲专区| 中文字字幕在线高清免费电影| 亚洲AV无码精品色午夜果冻不卡| 最近中文字幕免费2019| 久久国产亚洲精品| 亚洲国产精品无码久久久久久曰| 狠狠躁狠狠爱免费视频无码| 亚洲第一AAAAA片| AA免费观看的1000部电影| 免费播放美女一级毛片| 国产亚洲精品无码成人| 一二三四免费观看在线视频中文版 | 1000部拍拍拍18勿入免费视频下载 | 免费观看亚洲人成网站| 久久成人18免费网站| 久久国产亚洲精品无码| 日日AV拍夜夜添久久免费| aa级毛片毛片免费观看久| 亚洲熟妇无码久久精品| 国产jizzjizz视频免费看| 暖暖日本免费中文字幕| 亚洲欧美综合精品成人导航| 久久亚洲AV无码西西人体| 日本在线高清免费爱做网站| 国产精品高清免费网站| 久久亚洲最大成人网4438| 亚洲色精品88色婷婷七月丁香|