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

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

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

    konhon

    忘掉過去,展望未來。找回自我,超越自我。
    逃避不一定躲的過, 面對不一定最難過, 孤單不一定不快樂, 得到不一定能長久, 失去不一定不再擁有, 可能因為某個理由而傷心難過, 但我卻能找個理由讓自己快樂.

    Google

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      203 Posts :: 0 Stories :: 61 Comments :: 0 Trackbacks

    服務器:
    1.jsp
    <body>
    <form name="_ctl0" method="post" action="TestFileManager.aspx" id="_ctl0" enctype="multipart/form-data">
    <input type="hidden" name="__VIEWSTATE" value="dDwyNTIzNjA5NDU7Oz7rsE3eBYzQHDVtl+aTn96MvQW6PQ==" />
    <p>
    <input name="uploadfile1" id="uploadfile1" type="file" size="49" />
    <input type="submit" name="Button1" value="?" id="Button1" />
    </p>
    <p>
    <span id="Label1" style="width:459px;"></span>
    </p>
    <!-- Insert content here -->
    </form>
    </body>
    客戶端:
    首先創建一個到服務器http的請求
    HttpRequest request = new HttpRequest("http://服務器/1.jsp");
    第一次使用的是GET方式
    request.setMethod("GET");
    緊接著進行一些請求的屬性設置
    request.setRequestHeader("Cache-Control", "no-cache");
    這里保持連接,因為后面還要發送數據到服務器呢
    request.setRequestHeader("Connection", "Keep-Alive");
    下面是一些無關緊要的屬性設置了。
    request.setRequestHeader("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
    request.setRequestHeader("Accept-Encoding", "gzip, deflate");
    request.setRequestHeader("Accept-Language", "en-au");
    request.setRequestHeader("Referer", "http://服務器/1.jsp");
    request.setRequestHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3215; .NET CLR 1.0.3705)");
    構造好了連接請求,然后連接
    request.connect();
    緊接著提取Cookie值,在后文的post中可以用到。
    String strCookie = request.getResponseHeader("Set-Cookie");
    strCookie = strCookie.substring(0,strCookie.indexOf(";"));
    下面通過循環查找,提取__VIEWSTATE的值
    for ( int i = 0; i < nlist.getLength(); i++) {
    node = nlist.item(i);
    strName = getNodeAttributeValue(node,"name");
    if ( strName.equals("__VIEWSTATE") ) {
    strValue = getNodeAttributeValue(node,"value");
    break;
    }
    }
    往服務器組織發送數據
    DataOutputStream dos = new DataOutputStream(request.getOutputStream());
    dos.writeBytes("-----------------------------"+strBoundary);//這是每個要被發送數據間的間隔
    dos.writeBytes(" Content-Disposition: form-data; name="__VIEWSTATE"");
    dos.writeBytes(" "+strValue);
    dos.writeBytes(" -----------------------------"+strBoundary);
    這里面是發送文件的部分
    dos.writeBytes(" Content-Disposition: form-data; name="uploadfile1"; filename="" + strFileName + """);
    dos.writeBytes(" Content-Type: text/xml");
    dos.writeBytes(" ");
    dos.writeBytes(new String(data));
    dos.writeBytes(" -----------------------------"+strBoundary);
    dos.writeBytes(" Content-Disposition: form-data; name="Button1"");
    dos.writeBytes(" 上傳");
    dos.writeBytes(" -----------------------------"+strBoundary+"--");
    dos.writeBytes(" ");
    dos.close();
    posted on 2007-03-07 20:14 konhon 優華 閱讀(4267) 評論(1)  編輯  收藏

    Feedback

    # re: 用JAVA模擬POST發送數據 [未登錄] 2009-05-12 03:42 ck
    HttpRequest是什么東西呢?  回復  更多評論
      


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 特级毛片免费观看视频| 亚洲日本在线免费观看| 亚洲A∨午夜成人片精品网站| 久久精品a一国产成人免费网站| 成人免费视频一区| 免费va人成视频网站全| 亚洲一区无码中文字幕| 亚洲欧洲高清有无| 亚洲1区2区3区精华液| 国产成人无码免费看片软件| 久久aa毛片免费播放嗯啊| 久久受www免费人成_看片中文| 免费人成网站在线播放| 视频一区二区三区免费观看| 国产成人免费手机在线观看视频| 亚洲午夜无码片在线观看影院猛| 亚洲国色天香视频| 国产福利在线免费| 久久精品国产亚洲AV果冻传媒 | 视频免费在线观看| 嫖丰满老熟妇AAAA片免费看| 亚洲一区欧洲一区| 本道天堂成在人线av无码免费| 国产午夜亚洲精品午夜鲁丝片| 亚洲人成在线播放| 久久免费观看国产精品| 国产成人免费全部网站| 国产精品高清免费网站| 亚洲天堂中文资源| 中国videos性高清免费| 免费国产在线观看老王影院| yellow视频免费在线观看| 免费看大黄高清网站视频在线| 亚洲制服丝袜精品久久| 免费观看四虎精品国产永久| 亚洲国产精品久久久久秋霞小| 亚洲精品在线免费观看| 亚洲成熟xxxxx电影| 一级毛片免费视频| 亚洲AV成人精品日韩一区| 欧洲亚洲国产清在高|