zoukankan      html  css  js  c++  java
  • ps script http通信 2

    function httpGetFile(url, port){
       if(url.substr(0,7)=="http://")
    url=url.substr(7);
       if(!port) port=80;
       var
    domain=url.split("/")[0]+":"+port;
       var
    fileName=url.substr(url.lastIndexOf("/")+1);
       var call="GET ";
     
     if(url.indexOf("/")<0){
          call+="/";
       }else{
        
     call+=url.substr(url.indexOf("/"));
       }
       call+=" HTTP/1.1\n";
     
     call+="Host: "+domain+"\n\n";
       
       var reply = new String();
       var
    file = new File();
       file.encoding = "binary";
       file.open("w");
     
     var conn = new Socket();
       conn.encoding = "binary";
       if (conn.open
    (domain, "binary")) {
          conn.write (call);
          reply =
    conn.read(99999999999);
          reply = reply.split("\r\n").join("\n");
        
     reply = reply.split("\r").join("\n");
        
     file.write(reply.substr(reply.indexOf("\n\n")+2));
          file.close();
     
        file.rename(fileName);
          conn.close();
       }else{
        
     alert("CONNECTION TO DATABASE FAILED");
          reply = "";
       }
     
     return file;
    }

    // EXAMPLE:
    var
    gotFile=httpGetFile("http://www.ps-scripts.com/bb/templates/subSilver/images/logo1.gif");

    alert("GOT
    FILE "+gotFile.length);

    app.load(gotFile);

  • 相关阅读:
    ip netns
    PPT动手动脑1
    暑假作业日总结
    暑假作业日总结
    课前测试总结
    暑假作业日总结
    大二上每日总结
    暑假作业日总结
    大二上每日总结
    暑假作业日总结
  • 原文地址:https://www.cnblogs.com/fx2008/p/3098580.html
Copyright © 2011-2022 走看看