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

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

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

    posts - 23,comments - 66,trackbacks - 0
    from:http://blog.csdn.net/ambitiontan/archive/2006/01/05/571272.aspx

    服務器:
    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 2006-03-21 21:44 rd2pm 閱讀(2263) 評論(1)  編輯  收藏

    FeedBack:
    # re: 用JAVA模擬POST發送數據
    2006-12-20 09:36 | 王建平
    你的HttpRequest 在那個包里面?
      回復  更多評論
      

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


    網站導航:
     

    主站蜘蛛池模板: 亚洲人成影院在线观看| 一个人免费观看视频www| 亚洲国产精品狼友中文久久久| 亚洲色偷偷综合亚洲AV伊人蜜桃 | 无码人妻久久一区二区三区免费| 亚洲中文字幕无码久久2017| 一级特黄录像视频免费| 国产亚洲情侣一区二区无码AV | 亚洲av无码一区二区三区在线播放 | 亚洲精品美女久久777777| 国产精品免费看久久久香蕉| 亚洲人成人77777网站| 桃子视频在线观看高清免费视频| 亚洲精品天天影视综合网| 91精品视频在线免费观看| 亚洲精品国产情侣av在线| 欧洲精品成人免费视频在线观看| 亚洲日本中文字幕天天更新| 国产一级淫片免费播放电影| 一级毛片成人免费看a| 久久亚洲精品成人| 国产91色综合久久免费分享| 亚洲av无码专区首页| 亚洲精品色午夜无码专区日韩| 2020因为爱你带字幕免费观看全集| 亚洲一区免费视频| 国产精品免费小视频| 最近国语视频在线观看免费播放 | 最近2019中文字幕免费大全5| 亚洲国产成a人v在线观看| 精品久久久久久久免费人妻| 国产免费久久精品99久久| 77777_亚洲午夜久久多人| 免费无码看av的网站| 中文字幕手机在线免费看电影| 91嫩草亚洲精品| 亚洲午夜福利精品无码| 中文字幕免费视频| 美女露隐私全部免费直播| 亚洲精品中文字幕麻豆| 亚洲成av人片一区二区三区 |