HTTP协议multipart/form-data

http协议

  1. multipart/form-data 格式

    --${bound}  //分割符
    Content-Disposition: form-data; name="Filename"  
    
    HTTP.pdf  
    --${bound}  
    Content-Disposition: form-data; name="file000"; filename="HTTP协议详解.pdf"  
    Content-Type: application/octet-stream  
    
    %PDF-1.5  
    file content  
    %%EOF  
    --${bound}  
    Content-Disposition: form-data; name="Upload"  
    
    Submit Query  
    --${bound}-- 
    

    示例,格式必须保证一致,包括回车,各参数之间

    Header = {"Content-type" : "multipart/form-data, boundary=vadonmo"}  //分割符随意,一般尽量随机,避免和正文重复

    Data =  "--vadonmo\r\n" +  //分割符
            "content-disposition: form-data; name=\"userName\"\r\n" +  //参数名
            "\r\n" +   
            "Vadon Mo Wang\r\n" +  //参数值,与参数名之间两个回车
            "--vadonmo\r\n" +  //分隔符
            "content-disposition: form-data; name="pics"; filename=\"file1.jpg\"\r\n" +  //第二个参数名
            "Content-Type: image/jpeg\r\n" +  //MIME类型
            "\r\n" +  
            "...binary contents of file1.jpg ...\r\n" +  //参数名与参数值之间两个回车,值为二进制
            "--vadonmo--\r\n"  //结束分隔符

猜你喜欢

转载自blog.csdn.net/vadonmo/article/details/79568257