1

我之前在 cfloop 限制中发布了 cfhttp 帖子?使用 cfthread关于发出多个 CFHTTP 请求,我实现了在 JS 函数中发出 XMLHttpRequest 的解决方案,以从另一个文件调用我的 CFHTTP 请求。

我已经对此进行了修改,以便它在间隔计时器上运行,但我似乎有一个问题,即我只被主机允许每秒发出 3 个请求,但尽管我可以将间隔时间设置为每 7 秒我仍然最终超时,因为 CFHTTP 请求似乎挂起并且经常同时发出请求(这意味着它让我通过了阈值)。

我已经阅读了 Ben Nadel 关于使用 CFTHREAD 的帖子,但完全没有实现它们的乐趣。

我目前的基本流程是:-

  • Index.cfm 包含一个使用 XMLHttpRequest 调用 playerSearch.cfm 的 JS 函数
  • playerSearch.cfm 发出 CFHTTP 请求。
  • playerSearch.cfm 然后循环响应并显示循环中的当前项目,并提交另一个 CFHTTP 请求以对循环中的当前项目进行投标,如果它满足我的任何 IF 条件。
  • 然后,Index.cfm 每隔 X 秒就不断发出请求。

有没有办法可以将 CFHTTP 请求本身设置为每 X 秒发出一次请求(也许使用 CFTHREAD 中的睡眠功能?),我将如何在 CFTHREAD 中显示任何东西,因为我似乎无法做到?

此外,如果我能够让 CFHTTP 请求本身每隔 X 秒发出一次请求,那么我会更好地直接调用它并且它会不断循环吗?

任何反馈将不胜感激!

编辑:

索引.cfm

<script>

var searchTimer = null,
    searchInterval = 1000,
    startPosition = 0;

function startSearch() {
    if (searchTimer !== null) return;
    searchTimer = setInterval(function () {
        startPosition = startPosition + 16;
        var xhr = new XMLHttpRequest();
        xhr.open("GET", "playerSearch.cfm?startPosition="+startPosition, true);
        xhr.onload = function (e) {
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    document.getElementById("counter").innerHTML = xhr.response;
                } else {
                    // Error handling
                }
            }
        };
        xhr.onerror = function (e) {
            // Error handling
        };
        xhr.send(null);
    }, searchInterval);
}

function stopSearch() {
    clearInterval(searchTimer);
    searchTimer = null
}

</script>

playerSearch.cfm

<cfset Variables.startPosition = URL.startPosition />

<cfhttp url="https://utas.fut.ea.com/ut/game/fifa13/auctionhouse?type=player" method="post" result="getPlayer">
    <cfhttpparam type="header" name="Accept" value="application/json" />
    <cfhttpparam type="header" name="Accept-Language" value="en-GB" />
    <cfhttpparam type="header" name="Connection" value="keep-alive" />
    <cfhttpparam type="header" name="Content-Length" value="1" />
    <cfhttpparam type="header" name="Content-Type" value="application/json" />
    <cfhttpparam type="header" name="COOKIE" value="#Arguments.cookieString#">
    <cfhttpparam type="header" name="Host" value="utas.fut.ea.com" />
    <cfhttpparam type="header" name="Referer" value="http://cdn.easf.www.easports.com/soccer/static/flash/futFifaUltimateTeamPlugin/FifaUltimateTeam.swf" />
    <cfhttpparam type="header" name="User-Agent" value="Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36" />
    <cfhttpparam type="header" name="X-HTTP-Method-Override" value="GET" />
    <cfhttpparam type="header" name="X-UT-Embed-Error" value="true" />
    <cfhttpparam type="header" name="x-flash-version" value="11,7,700,224" />
    <cfhttpparam type="header" name="X-UT-SID" value="#Arguments.sessionID#" />
</cfhttp>

<cfif getPlayer.StatusCode EQ "200 OK">
    <!--- DESERIALIZE RETURNED JSON SO CAN LOOP ROUND EACH RESULT --->
    <cfset Variables.searchResults = DeserializeJSON(getPlayer.FileContent) />

    <!--- IF SEARCH RESULTS RETURNED --->
        <cfset Variables.numResults = ArrayLen(Variables.searchResults.auctionInfo) />
        <cfset Variables.bidsMade = 0 />

        <table width="900" cellpadding="0" cellspacing="0">
            <tr>
                <th width="100" align="left" class="heading">Player Name</th>
                <th width="70" align="left" class="heading">Rating</th>
                <th width="50" align="left" class="heading">Formation</th>
                <th width="80" align="left" class="heading">Position</th>
                <th width="80" align="left" class="heading">Bid Status</th>
                <th width="100" align="left" class="heading">Starting Price</th>
                <th width="80" align="left" class="heading">BIN Price</th>
                <th width="80" align="left" class="heading">Current Bid</th>
                <th width="80" align="left" class="heading">My Bid</th>
                <th width="120" align="left" class="heading">Ends</th>
            </tr>
            <cfloop from="1" to="#Variables.numResults#" index="i"> 

                <cfscript>

                    // DEFAULT BID AMOUNT
                    Variables.bidAmount = 0;

                    // SET BID AMOUNT
                    // IF ITEM HAS BUY NOW PRICE AND IT IS LESS THAN QUICK SELL VALUE THEN BID THAT AMOUNT
                    if (Variables.searchResults.auctionInfo[i].buyNowPrice NEQ 0 AND Variables.searchResults.auctionInfo[i].buyNowPrice LT Variables.searchResults.auctionInfo[i].itemData.discardValue) {
                        Variables.bidAmount = Variables.searchResults.auctionInfo[i].buyNowPrice;
                    }
                    // ELSE IF QUICK SELL VALUE IS 228,231,235,238,242,245 OR 249 BID 200
                    else if (ListFind("228,231,235,238,242,245,249",Variables.searchResults.auctionInfo[i].itemData.discardValue) AND Variables.searchResults.auctionInfo[i].startingBid LTE 200 AND Variables.searchResults.auctionInfo[i].currentBid LT 200) {
                        Variables.bidAmount = 200;
                    }
                    // ELSE IF QUICK SELL VALUE IS 252,256,259 OR 300 BID 250
                    else if (ListFind("252,256,259,300",Variables.searchResults.auctionInfo[i].itemData.discardValue) AND Variables.searchResults.auctionInfo[i].startingBid LTE 250 AND Variables.searchResults.auctionInfo[i].currentBid LT 250) {
                        Variables.bidAmount = 250;
                    }

                    // GET MY CURRENT COIN TOTAL
                    Variables.getCoinTotal = Application.cfcs.Club.getCreditsTotal(SESSION.phishingKey,SESSION.sessionKey);
                    Variables.curCoinsData = DeserializeJSON(Variables.getCoinTotal.FileContent);
                    Variables.curCoins = Variables.curCoinsData.credits;

                    // IF I CURRENTLY HAVE ENOUGH COINS IN ACCOUNT PLACE BID
                    if (StructKeyExists(Variables,"curCoins") AND Variables.bidAmount NEQ 0 AND Variables.bidAmount LT Variables.curCoins) {

                        <cfset Variables.bidData = '{ "bid": ' & Variables.bidAmount & ' }'>
                        <cfset Variables.bidDataLength = Len(Variables.bidData) />

                        <cfhttp url="https://utas.fut.ea.com/ut/game/fifa13/trade/" & Variables.searchResults.auctionInfo[i].tradeID & "/bid" method="POST" result="makeBid">
                            <cfhttpparam type="header" name="Accept" value="application/json" />
                            <cfhttpparam type="header" name="Connection" value="keep-alive" />
                            <cfhttpparam type="header" name="Content-Type" value="application/json" />
                            <cfhttpparam type="header" name="Content-Length" value="#Variables.bidDataLength#" />
                            <cfhttpparam type="header" name="Host" value="utas.fut.ea.com" />
                            <cfhttpparam type="header" name="Referer" value="http://cdn.easf.www.easports.com/soccer/static/flash/futFifaUltimateTeamPlugin/FifaUltimateTeam.swf" />
                            <cfhttpparam type="header" name="X-HTTP-Method-Override" value="PUT" />
                            <cfhttpparam type="header" name="X-UT-SID" value="#SESSION.sessionKey#" />
                            <cfhttpparam type="header" name="COOKIE" value="#SESSION.phishingKey#">     
                            <cfhttpparam type="header" name="User-Agent" value="Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36" />
                            <cfhttpparam type="body" value="#Variables.bidData#" /> 
                        </cfhttp>

                        Variables.bidsMade = Variables.bidsMade + 1;

                    } else {

                        Variables.bidAmount = 0;

                    }
                </cfscript>
                <cfoutput>
                    <tr>
                        <td align="left">#Variables.searchResults.auctionInfo[i].itemData.assetID#</td>
                        <td align="left">
                            #Variables.searchResults.auctionInfo[i].itemData.rating# 
                            <cfif Variables.searchResults.auctionInfo[i].itemData.rareFlag EQ 0>
                                &nbsp;
                            <cfelseif Variables.searchResults.auctionInfo[i].itemData.rareFlag EQ 1>
                                (Rare)
                            <cfelse>
                                (Something else)
                            </cfif>
                        </td>
                        <td align="left">#Variables.searchResults.auctionInfo[i].itemData.formation#</td>
                        <td align="left">#Variables.searchResults.auctionInfo[i].itemData.preferredPosition#</td>
                        <td align="left">#Variables.searchResults.auctionInfo[i].bidState#</td>
                        <td align="left">#Variables.searchResults.auctionInfo[i].startingBid#</td>
                        <td align="left">#Variables.searchResults.auctionInfo[i].buyNowPrice#</td>
                        <td align="left">#Variables.searchResults.auctionInfo[i].currentBid#</td>
                        <td align="left">#Variables.bidAmount#</td>
                        <td align="left">
                            <cfif Variables.searchResults.auctionInfo[i].tradeState EQ "active">
                                <cfset timeLeft = Variables.searchResults.auctionInfo[i].expires />
                                <cfset auctionEnds = DateAdd("s",timeLeft,Now()) />
                                #DateFormat(Variables.auctionEnds,"dd/mm/yyyy")# #TimeFormat(Variables.auctionEnds,"HH:mm:ss")#
                            <cfelse>
                                Ended
                            </cfif>
                        </td>
                    </tr>
                </cfoutput>
            </cfloop>
        </table>
        <br /><br />Bids Made: <cfoutput>#Variables.bidsMade#</cfoutput>
<cfelse><br />
    The search returned an error.
    <cfdump var="#getPlayer#">
</cfif>
4

0 回答 0