簡體   English   中英

繞過CloudFlare超時100秒

[英]Bypassing CloudFlare's time-out of 100 seconds

我正在嘗試AJAX-ify我的報告,以便繞過CloudFlare對通過其站點運行的請求施加的100秒超時。

請參閱是否可以增加CloudFlare超時?

我做了以下事情:

function ajaxReport() {
    var seconds = prompt("Please enter how many seconds you want the report to run", "5");
    $('#imgWaiting').show();
    $.post("post/post_ajaxReport.jsp",
  {
    theParam:seconds
  },function(data) {
    $('#imgWaiting').hide();
    window.location=data;
 });

}

以及post_ajaxReport.jsp的以下內容

<%
 int theParam=myFunctionToConvertStringToInt(request.getParameter("theParam"));
int a=theParam/60;
int b=theParam-a*60;
String query="WAITFOR DELAY '00:"+a+":"+b+"';";
double d=myCustomCodeToRunQuery(query);
String fileName=createReport();
%>
<%=fileName%>

該代碼在100秒內運行良好。 但是超過100秒沒有工作。

有任何想法嗎?

反饋后更新

我的報告在沒有AJAX的情況下工作正常(盡管CloudFlare有100秒的超時)。 我試圖將它們轉換為AJAX,以避免灰色陰影子域,因為我不想公開我的IP地址。 如果我要對一個子域進行灰色雲計算,我會在原始代碼上執行此操作,這比AJAX要簡單得多! 我的問題是“如何修復我的AJAX代碼,這樣我就可以避免100秒超時,但沒有暴露我的IP地址的缺點......”

如果其他人有同樣的問題,我發布我最終如何工作。 我放棄了嘗試使用AJAX來運行報告,而是通過線程運行報告,但使用AJAX“輪詢”以檢查報告是否已創建。 我所做的基本如下。

請注意,我從代碼中刪除了大量內容,例如安全例程和錯誤檢查例程,只是為了給出基本框架。

我創建了一個名為ThreadMyReport的java類

public class ThreadMyReport implements Runnable {

    String fileID = "";
    Date dateOfReport = null;

    public ThreadMyReport(Date dateOfReport) {
        this.fileID= "MyReport_" + UUID.randomUUID();
        this.dateOfReport = dateOfReport;
    }

    public void run() {
        int a = ReportMyReport.loadAndSaveMyReport(dateOfReport, fileID);
    }


    public String getFileID() {
        return fileID;
    }
}

我可以在ReportMyReport.loadAndSaveMyReport中找到生成報告的所有原始代碼。 報告完成后,它會在服務器上保存帶有fileName fileID的文件。

然后我開始一個線程來運行報告

    ThreadMyReport a  = new ThreadMyReport(theDate);
    Thread theThread=new Thread(a);
    theThread.start();
    fileID=a.getFileID();

然后我添加了一個javascript例程,每秒通過AJAX檢查文件是否已創建,如果已創建,則顯示報告。

<SCRIPT language="javascript">


    var myVar;
    myVar=setInterval(function (){
    $.post("post/post_checkReportReady_xml.jsp", {
       generatedReport: '<%=fileID%>'
    }, function(data) {
       if (data.indexOf("produced")>-1) {
           clearInterval(myVar);
           //display report
       }
       if (data.indexOf("failed")>-1) {
           clearInterval(myVar);
       }
    });

}, 1000);
        </SCRIPT>

AJAX代碼如下所示:

     <%
    String result="";

    String generatedReport=(request.getParameter("generatedReport"));

    if(!"".equals(generatedReport)) {
        String fileName2="My directory/"+generatedReport+".xlsm"; 
        java.io.File f = new java.io.File(fileName2);
        if(f.exists()) { 
            result="produced";
        }
    }
}

%>
<%=result%>

由於cloudflare不緩存html或xhr,您可以greycloud子域,但在服務器上使用它作為別名。 例如...

在CloudFlare dns中:

  • www 123.123.123.123 =橙色(受保護)
  • ajax 123.123.123.123 =灰色(僅限dns)

在您的網站控制面板中添加ajax.mydomain.com作為別名。

最后,在你的代碼中使用擊中你的服務器的fqdn繞過cloudflare。

function ajaxReport() {
    var seconds = prompt("Please enter how many seconds you want the report to run", "5");
    $('#imgWaiting').show();
    $.post("//ajax.mydomain.com/post/post_ajaxReport.jsp",
  {
    theParam:seconds
  },function(data) {
    $('#imgWaiting').hide();
    window.location=data;
 });
}

這確實暴露了您的IP地址。 但是根據返回的內容,應該幾乎沒有性能損失。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM