欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
java socket實(shí)現http

import java.net.Socket;
import java.io.OutputStream;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.File;


public class Httpclient {
public String boundary = "-----=_Part_4_20727434.1184328927468";
private static final byte CR = (byte)'\r';
private static final byte LF = (byte)'\n';
private static final byte[] CRLF = new byte[]{CR,LF};
private String contentType = "multipart/form-data; type=\"text/xml\"; start=\"<A1DD1D17CA63B74B4021F4C2EE55D783>\"; .boundary="+boundary;
private Socket socket;
private String host; 
private int port;
private String uri;
private byte[] key; //AES128CBC的密鑰
private byte[] iv;   //AES128CBC的初始向量

public void setUri(String uri)
{
   this.uri=uri;
}
public void setKey(byte[] key)
{this.key =key;}

public void setIv(byte[] iv)
{this.iv =iv;}

public Httpclient(String host,int port){
        this.host = host;
        this.port = port;
}

private void openServer() throws Exception {
        socket = new Socket(host,port);
}

private void closeServer() {
   try{
        if(socket!=null){ socket.close();}
        System.out.println("END");
   }
        catch(Exception e){e.printStackTrace();}
   }


private void write(OutputStream out,String msg) throws IOException 
    { out.write(msg.getBytes());
    }


private void addHead(long contentLength,OutputStream out) throws   IOException {        
        write(out,"POST "+uri+" HTTP/1.1");
        out.write(CRLF);
        write(out,"Content-Type: "+contentType);
        out.write(CRLF);
        write(out,"Accept: application/soap+xml, application/dime, multipart/related, text/*"); 
        out.write(CRLF);
        write(out,"User-Agent: Axis/1.2.1");
        out.write(CRLF);
        write(out,"Host:"+host+":"+Integer.toString(port));
        out.write(CRLF);
        write(out,"Cache-Control: no-cache");
        out.write(CRLF);
        write(out,"Pragma: no-cache");
        out.write(CRLF);
        write(out,"SOAPAction: \"\"");
        out.write(CRLF);
        write(out,"Content-Length: "+contentLength);
        out.write(CRLF);
        out.write(CRLF);    
       
}

public void addgethead(OutputStream out) throws   IOException
{
   write(out,"GET "+uri+" HTTP/1.1");
        out.write(CRLF);
        write(out,"Accept: */*");
        out.write(CRLF);
        write(out,"Accept-Language: zh-cn"); 
        out.write(CRLF);
        write(out,"UA-CPU: x86");
        out.write(CRLF);
        write(out,"Accept-Encoding: gzip, deflate");
        out.write(CRLF);
        write(out,"User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)");
        out.write(CRLF);
        write(out,"Host:"+host+":"+Integer.toString(port));
        out.write(CRLF); 
        write(out,"Connection: Keep-Alive");
        out.write(CRLF);
        out.write(CRLF);   
}

private void addXML(File file,OutputStream out) throws   IOException {
   write(out,boundary);
        out.write(CRLF);       
        write(out,"Content-Type: "+getType(file)); out.write(CRLF);
        write(out,"Content-Transfer-Encoding: binary");out.write(CRLF);
        write(out,"Content-Id: <A1DD1D17CA63B74B4021F4C2EE55D783>");
        out.write(CRLF);
        out.write(CRLF);
        InputStream is = new FileInputStream(file);
        byte[] b = new byte[1024];
        int count = is.read(b);
        while(count!=-1){
        out.write(b,0,count);
            count = is.read(b);
        }
        is.close();
        out.write(CRLF);
        } 
private void addBody(File file,OutputStream out) throws IOException {
   write(out,boundary);
        out.write(CRLF);
       
        write(out,"Content-Type: "+getType(file)); out.write(CRLF);
        write(out,"Content-Transfer-Encoding: binary");out.write(CRLF);
        write(out,"Content-Id: <A1DD1D17CA63B74B4021F4C2EE55D783>");
        out.write(CRLF);
        out.write(CRLF);
        InputStream is = new FileInputStream(file);
        ASE128CBC f1=new ASE128CBC();
        try{
        f1.init(0, key, iv) ;   
        byte[] cipher=new byte[1024]; //生成的密文
        byte[] b = new byte[1024];      //讀取的明文 
        int count = is.read(b);
        f1.update(b, 0, count, cipher, 0);//加密
        while(count!=-1){
        out.write(cipher,0,count);
        if(count<1024)break;
            count = is.read(b);
            f1.update(b, 0, count, cipher, 0);
        }
        is.close();
        out.write(CRLF);
        }catch(Exception e){e.printStackTrace();}
       }

public void uploadFile(File[] files) throws Exception {
   openServer();
   OutputStream out = socket.getOutputStream();
   ByteArrayOutputStream bos = new ByteArrayOutputStream();
   ByteArrayOutputStream bos1 = new ByteArrayOutputStream();
   addXML(files[0],bos);
   for(int i=1;i<files.length;i++){
             if(files[i]==null)break;
    addBody(files[i],bos);
   }
   write(bos,boundary+"--");
   bos.write(CRLF);
   addHead(bos.size(),bos1);
   // addgethead(bos1);
   bos.writeTo(bos1);
   bos1.writeTo(out);
   bos.close();
   bos1.close(); 
   out.flush();
   closeServer();
   }
public String getType(File file){
   String tem=file.toString();
   if(tem.endsWith(".jpg"))tem="img/jpeg";
   else if(tem.endsWith(".xml"))tem="text/xml";
   else tem="Unknown";
    return tem;
  
}

}

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
RFC1867協(xié)議客戶(hù)端實(shí)現
FLASH與服務(wù)器通訊 (JAVA)
面試突擊:什么是粘包和半包?怎么解決?
徹底轉變流,第 1 部分
C#.net同步異步SOCKET通訊和多線(xiàn)程總結
服務(wù)器+客戶(hù)端的聊天程序 - 51CTO.COM
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久