首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >改进CFHTTP响应时间

改进CFHTTP响应时间
EN

Stack Overflow用户
提问于 2013-12-21 12:55:25
回答 1查看 1.5K关注 0票数 4

我有一个API,它登录一个帐户,然后对我想通过CFHTTP请求进行投标的项目执行搜索,如下所示。

Search.cfm:

代码语言:javascript
复制
<cfinclude template="logMeIn.cfm" />

<cfhttp url="https://utas.fut.ea.com/ut/game/fifa14/transfermarket?maxb=1800000&start=0&num=16&type=player&maskedDefId=158023" method="POST" result="Get">
    <cfhttpparam type="header" name="Cache-Control" value="no-cache" />
    <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="GET" />
    <cfhttpparam type="header" name="X-UT-PHISHING-TOKEN" value="#ListLast(Session.searchAccount40PhishingKey,'=')#" />
    <cfhttpparam type="header" name="X-UT-SID" value="#Session.searchAccount40SessionKey#" />
</cfhttp>

logMeIn.cfm:

代码语言:javascript
复制
<cfscript>
    Variables.email = "XYZ@example.com";
    Variables.password = "password";
    Variables.secretAnswer = "secretAnswer";
    Session.searchAccountGamertag = "WirierJupiter11";
    Variables.doReload = 0;
    Variables.deviceView = "device=not_mobile";
</cfscript>

<cfhttp url="http://www.easports.com/uk/fifa/football-club/ultimate-team" method="GET" result="stage1" redirect="false">
    <cfhttpparam type="header" name="Accept" value="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" />
    <cfhttpparam type="header" name="Accept-Encoding" value="gzip, deflate" />
    <cfhttpparam type="header" name="Accept-Language" value="en-US, en;q=0.5" />
    <cfhttpparam type="header" name="Connection" value="keep-alive" />
    <cfhttpparam type="header" name="Host" value="www.easports.com" />
    <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" />
</cfhttp>

<cfif StructKeyExists(Stage1.ResponseHeader,"Location")>
    <cfscript>
        Variables.stage2URL = Stage1.ResponseHeader['Location'];
        Variables.returnedCookies = Stage1.ResponseHeader['Set-Cookie'];
        Variables.easfcWebSessionStr = Variables.returnedCookies[1];
        Variables.easfcWebSession = ListFirst(Variables.easfcWebSessionStr,";");
        Variables.hlStr = Variables.returnedCookies[2];
        Variables.hl = ListFirst(Variables.hlStr,";");
        Variables.xsrfTokenStr = Variables.returnedCookies[3];
        Variables.xsrfToken = ListFirst(Variables.xsrfTokenStr,";");
    </cfscript>
    <cfhttp url="#Variables.stage2URL#" method="GET" result="Stage2" redirect="false">
        <cfhttpparam type="header" name="Accept" value="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" />
        <cfhttpparam type="header" name="Accept-Encoding" value="gzip, deflate" />
        <cfhttpparam type="header" name="Accept-Language" value="en-US, en;q=0.5" />
        <cfhttpparam type="header" name="Connection" value="keep-alive" />
        <cfhttpparam type="header" name="Host" value="accounts.ea.com" />
        <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" />
    </cfhttp>
<cfelse>
    <cfset Variables.doReload = 1 />
</cfif>

<cfif StructKeyExists(Variables,"Stage2") AND StructKeyExists(Stage2.ResponseHeader,"Location")>
    <cfscript>
        Variables.stage3URL = Stage2.ResponseHeader['Location'];
    </cfscript>
    <cfhttp url="#Variables.stage3URL#" method="GET" result="Stage3" redirect="false">
        <cfhttpparam type="header" name="Accept" value="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" />
        <cfhttpparam type="header" name="Accept-Encoding" value="gzip, deflate" />
        <cfhttpparam type="header" name="Accept-Language" value="en-US, en;q=0.5" />
        <cfhttpparam type="header" name="Connection" value="keep-alive" />
        <cfhttpparam type="header" name="Host" value="signin.ea.com" />
        <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" />
    </cfhttp>
<cfelse>
    <cfset Variables.doReload = 1 />
</cfif>

<cfif StructKeyExists(Variables,"Stage3") AND StructKeyExists(Stage3.ResponseHeader,"Location")>
    <cfscript>
        Variables.stage4URL = Stage3.ResponseHeader['Location'];
        Variables.jSessionStr = Stage3.ResponseHeader['Set-Cookie'];
        Variables.jSession = ListFirst(Variables.jSessionStr,";");
    </cfscript>

    <cfhttp url="#Variables.stage4URL#" method="GET" result="Stage4" redirect="false">
        <cfhttpparam type="header" name="Accept" value="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" />
        <cfhttpparam type="header" name="Accept-Encoding" value="gzip, deflate" />
        <cfhttpparam type="header" name="Accept-Language" value="en-US, en;q=0.5" />
        <cfhttpparam type="header" name="Connection" value="keep-alive" />
        <cfhttpparam type="header" name="Cookie" value="#Variables.jSession#" />
        <cfhttpparam type="header" name="Host" value="signin.ea.com" />
        <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" />
    </cfhttp>

    <cfscript>
        Variables.bodyContent = "email=#Variables.email#&password=#Variables.password#&_rememberMe=on&rememberMe=on&_eventId=submit&facebookAuth=";
        Variables.contentLength = Len(Variables.bodyContent);
    </cfscript>

    <cfhttp url="#Variables.stage4URL#" method="POST" result="Stage5" redirect="false">
        <cfhttpparam type="header" name="Accept" value="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" />
        <cfhttpparam type="header" name="Accept-Encoding" value="gzip, deflate" />
        <cfhttpparam type="header" name="Accept-Language" value="en-US, en;q=0.5" />
        <cfhttpparam type="header" name="Cache-Control" value="no-cache" />
        <cfhttpparam type="header" name="Connection" value="keep-alive" />
        <cfhttpparam type="header" name="Content-Length" value="#Variables.contentLength#" />
        <cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded" />
        <cfhttpparam type="header" name="Cookie" value="#Variables.jSession#" />
        <cfhttpparam type="header" name="Host" value="signin.ea.com" />
        <cfhttpparam type="header" name="Referer" value="#Variables.stage4URL#" />
        <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.bodyContent#" />
    </cfhttp>
<cfelse>
    <cfset Variables.doReload = 1 />
</cfif>

<cfif StructKeyExists(Variables,"Stage5") AND StructKeyExists(Stage5.ResponseHeader,"Location")>
    <cfscript>
        Variables.stage6URL = Stage5.ResponseHeader['Location'];
        Variables.returnedCookies = Stage5.ResponseHeader['Set-Cookie'];
        Variables.webunStr = Variables.returnedCookies[3];
        Variables.webun = ListFirst(Variables.webunStr,";");
        Variables.isPogoStr = Variables.returnedCookies[4];
        Variables.isPogo = ListFirst(Variables.isPogoStr,";");
    </cfscript>
    <cfhttp url="#Variables.stage6URL#" method="GET" result="Stage6" redirect="false">
        <cfhttpparam type="header" name="Accept" value="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" />
        <cfhttpparam type="header" name="Accept-Encoding" value="gzip, deflate" />
        <cfhttpparam type="header" name="Accept-Language" value="en-US, en;q=0.5" />
        <cfhttpparam type="header" name="Cache-Control" value="no-cache" />
        <cfhttpparam type="header" name="Connection" value="keep-alive" />
        <cfhttpparam type="header" name="Cookie" value="s_sivo=US%3AORIGIN%3ANONE; s_cc=true; s_ria=flash%2010%7Csilverlight%202.9; s_pv=NA%3AUS%3ASTORE%3ANONE%3ASTORE%3ANONE%3AORIGIN%3ANONE%3ALOGIN; s_nr1=1379427845791-NEW; s_sq=%5B%5BB%5D%5D; __utma=103303007.1129861060.1379427834.1379427834.1379427834.1; __utmb=103303007.1.10.1379427834; __utmc=103303007; __utmz=103303007.1379427834.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); s_ppv=85">
        <cfhttpparam type="header" name="Host" value="accounts.ea.com" />
        <cfhttpparam type="header" name="Referer" value="#Variables.stage4URL#" />
        <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" />
    </cfhttp>
<cfelse>
    <cfset Variables.doReload = 1 />
</cfif>

<cfif StructKeyExists(Variables,"Stage6") AND StructKeyExists(Stage6.ResponseHeader,"Location")>
    <cfscript>
        Variables.stage7URL = Stage6.ResponseHeader['Location'];
        Variables.returnedCookies = Stage6.ResponseHeader['Set-Cookie'];
        Variables.sidStr = Variables.returnedCookies[1];
        Variables.sid = ListFirst(Variables.sidStr,";");
        Variables.remidStr = Variables.returnedCookies[2];
        Variables.remid = ListFirst(Variables.remidStr,";");
        Variables.cookieStr = Variables.easfcWebSession & "; " & Variables.hl & "; " & Variables.xsrfToken;
    </cfscript>
    <cfhttp url="#Variables.stage7URL#" method="GET" result="Stage7" redirect="false">
        <cfhttpparam type="header" name="Accept" value="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" />
        <cfhttpparam type="header" name="Accept-Encoding" value="gzip, deflate" />
        <cfhttpparam type="header" name="Accept-Language" value="en-US, en;q=0.5" />
        <cfhttpparam type="header" name="Cache-Control" value="no-cache" />
        <cfhttpparam type="header" name="Connection" value="keep-alive" />
        <cfhttpparam type="header" name="Cookie" value="#Variables.cookieStr#" />
        <cfhttpparam type="header" name="Host" value="www.easports.com" />
        <cfhttpparam type="header" name="Pragma" value="no-cache" />
        <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" />
    </cfhttp>
<cfelse>
    <cfset Variables.doReload = 1 />
</cfif>

<cfif StructKeyExists(Variables,"Stage7") AND StructKeyExists(Stage7.ResponseHeader,"Location")>
    <cfscript>
        Variables.stage8URL = Stage7.ResponseHeader['Location'];
        Variables.easfcWebSessionStr = Stage7.ResponseHeader['Set-Cookie'];
        Variables.easfcWebSession = ListFirst(Variables.easfcWebSessionStr,";");
        Variables.cookieStr = Variables.easfcWebSession & "; " & Variables.hl & "; " & Variables.xsrfToken;
    </cfscript>
    <cfhttp url="#Variables.stage8URL#" method="GET" result="Stage8" redirect="false">
        <cfhttpparam type="header" name="Accept" value="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" />
        <cfhttpparam type="header" name="Accept-Encoding" value="gzip, deflate" />
        <cfhttpparam type="header" name="Accept-Language" value="en-US, en;q=0.5" />
        <cfhttpparam type="header" name="Cache-Control" value="no-cache" />
        <cfhttpparam type="header" name="Connection" value="keep-alive" />
        <cfhttpparam type="header" name="Cookie" value="#Variables.cookieStr#" />
        <cfhttpparam type="header" name="Host" value="www.easports.com" />
        <cfhttpparam type="header" name="Pragma" value="no-cache" />
        <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" />
    </cfhttp>
<cfelse>
    <cfset Variables.doReload = 1 />
</cfif>

<cfif StructKeyExists(Variables,"Stage8") AND StructKeyExists(Stage8.ResponseHeader,"Set-Cookie")>
    <cfscript>
        Variables.stage9URL = "http://www.easports.com/iframe/fut/?locale=en_GB&baseShowoffUrl=http%3A%2F%2Fwww.easports.com%2Fuk%2Ffifa%2Ffootball-club%2Fultimate-team%2Fshow-off&guest_app_uri=http%3A%2F%2Fwww.easports.com%2Fuk%2Ffifa%2Ffootball-club%2Fultimate-team";
        Variables.returnedCookies = Stage8.ResponseHeader['Set-Cookie'];
        Variables.deviceView = ListFirst(Variables.returnedCookies,";");
        Variables.cookieStr = Variables.cookieStr & "; " & Variables.deviceView;
    </cfscript>
    <cfhttp url="#Variables.stage9URL#" method="GET" result="Stage9" redirect="false">
        <cfhttpparam type="header" name="Accept" value="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" />
        <cfhttpparam type="header" name="Accept-Encoding" value="gzip, deflate" />
        <cfhttpparam type="header" name="Accept-Language" value="en-US, en;q=0.5" />
        <cfhttpparam type="header" name="Connection" value="keep-alive" />
        <cfhttpparam type="header" name="Cookie" value="#Variables.cookieStr#" />
        <cfhttpparam type="header" name="Host" value="www.easports.com" />
        <cfhttpparam type="header" name="Referer" value="http://www.easports.com/uk/fifa/football-club/ultimate-team" />
        <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" />
    </cfhttp>
<cfelse>
    <cfset Variables.doReload = 1 />
</cfif>

<cfif StructKeyExists(Variables,"Stage9") AND StructKeyExists(Stage9.ResponseHeader,"Location")>
    <cfscript>
        Variables.stage10URL = Stage9.ResponseHeader['Location'];
        Variables.futWebStr = Stage9.ResponseHeader['Set-Cookie'];
        Variables.futWeb = ListFirst(Variables.futWebStr,";");
        Variables.cookieStr = Variables.remid & "; " & Variables.sid;
    </cfscript>
    <cfhttp url="#Variables.stage10URL#" method="GET" result="Stage10" redirect="false">
        <cfhttpparam type="header" name="Accept" value="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" />
        <cfhttpparam type="header" name="Accept-Encoding" value="gzip, deflate" />
        <cfhttpparam type="header" name="Accept-Language" value="en-US, en;q=0.5" />
        <cfhttpparam type="header" name="Connection" value="keep-alive" />
        <cfhttpparam type="header" name="Cookie" value="#Variables.cookieStr#" />
        <cfhttpparam type="header" name="Host" value="accounts.ea.com" />
        <cfhttpparam type="header" name="Referer" value="http://www.easports.com/uk/fifa/football-club/ultimate-team" />
        <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" />
    </cfhttp>
<cfelse>
    <cfset Variables.doReload = 1 />
</cfif>

<cfif StructKeyExists(Variables,"Stage10") AND StructKeyExists(Stage10.ResponseHeader,"Location")>
    <cfscript>
        Variables.stage11URL = Stage10.ResponseHeader['Location'];
        Variables.sidStr = Stage10.ResponseHeader['Set-Cookie'];
        Variables.sid = ListFirst(Variables.sidStr,";");
        Variables.cookieStr = Variables.futWeb & "; " & Variables.easfcWebSession & "; " & Variables.hl & "; " & Variables.xsrfToken & "; " & Variables.deviceView;
    </cfscript>
    <cfhttp url="#Variables.stage11URL#" method="GET" result="Stage11" redirect="false">
        <cfhttpparam type="header" name="Accept" value="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" />
        <cfhttpparam type="header" name="Accept-Encoding" value="gzip, deflate" />
        <cfhttpparam type="header" name="Accept-Language" value="en-US, en;q=0.5" />
        <cfhttpparam type="header" name="Connection" value="keep-alive" />
        <cfhttpparam type="header" name="Cookie" value="#Variables.cookieStr#" />
        <cfhttpparam type="header" name="Host" value="www.easports.com" />
        <cfhttpparam type="header" name="Referer" value="http://www.easports.com/fifa/football-club/ultimate-team" />
        <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" />
    </cfhttp>
<cfelse>
    <cfset Variables.doReload = 1 />
</cfif>

<cfif StructKeyExists(Variables,"Stage11") AND StructKeyExists(Stage11.ResponseHeader,"Location")>
    <cfscript>
        Variables.stage12URL = Stage11.ResponseHeader['Location'];
        Variables.futWebStr = Stage11.ResponseHeader['Set-Cookie'];
        Variables.futWeb = ListFirst(Variables.futWebStr,";");
        Session.searchAccountCookie = Variables.futWeb & "; " & Variables.easfcWebSession & "; " & Variables.hl & "; " & Variables.xsrfToken & "; " & Variables.deviceView;
    </cfscript>
    <cfhttp url="#Variables.stage12URL#" method="GET" result="Stage12" redirect="false">
        <cfhttpparam type="header" name="Accept" value="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" />
        <cfhttpparam type="header" name="Accept-Language" value="en-US, en;q=0.5" />
        <cfhttpparam type="header" name="Connection" value="keep-alive" />
        <cfhttpparam type="header" name="Cookie" value="#Session.searchAccountCookie#" />
        <cfhttpparam type="header" name="Host" value="www.easports.com" />
        <cfhttpparam type="header" name="Referer" value="http://www.easports.com/fifa/football-club/ultimate-team" />
        <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" />
    </cfhttp>
<cfelse>
    <cfset Variables.doReload = 1 />
</cfif>

<cfif StructKeyExists(Session,"searchAccountCookie")>
    <cfscript>
        Variables.data = '{ "isReadOnly": false, "sku": "FUT14WEB", "clientVersion": 1, "nuc": 1000215983198, "nucleusPersonaId": 948682854"nucleusPersonaDisplayName": "WirierJupiter11", "nucleusPersonaPlatform": "360", "locale": "en-GB", "method": "authcode", "priorityLevel":4, "identification": { "authCode": "" } }';
        Variables.dataLength = Len(Variables.data);
    </cfscript>
    <cfhttp url="http://www.easports.com/iframe/fut/p/ut/auth" method="POST" result="sessionIDRequest">
        <cfhttpparam type="header" name="Accept" value="application/json, text/javascript" />
        <cfhttpparam type="header" name="Accept-Language" value="en-US, en;q=0.5" />
        <cfhttpparam type="header" name="Connection" value="keep-alive" />
        <cfhttpparam type="header" name="Content-Length" value="#Variables.dataLength#" />
        <cfhttpparam type="header" name="Content-Type" value="application/json" />
        <cfhttpparam type="header" name="Cookie" value="#Session.searchAccountCookie#" />
        <cfhttpparam type="header" name="Easw-Session-Data-Nucleus-ID" value="1000215983198" />
        <cfhttpparam type="header" name="Host" value="www.easports.com" />
        <cfhttpparam type="header" name="Pragma" value="no-cache" />
        <cfhttpparam type="header" name="Referer" value=" http://www.easports.com/iframe/fut/?baseShowoffUrl=http%3A%2F%2Fwww.easports.com%2Fuk%2Ffifa%2Ffootball-club%2Fultimate-team%2Fshow-off&guest_app_uri=http%3A%2F%2Fwww.easports.com%2Fuk%2Ffifa%2Ffootball-club%2Fultimate-team&locale=en_GB">
        <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-UT-Embed-Error" value="true" />
        <cfhttpparam type="header" name="X-UT-Route" value="https://utas.fut.ea.com:443" />
        <cfhttpparam type="header" name="X-Requested-With" value="XMLHttpRequest" />
        <cfhttpparam type="body" value="#Variables.data#" />
    </cfhttp>
<cfelse>
    <cfset Variables.doReload = 1 />
</cfif>

<cfif StructKeyExists(Variables,"sessionIDRequest") AND Variables.sessionIDRequest.FileContent NEQ "Connection Failure" AND Variables.sessionIDRequest.StatusCode NEQ "500 Internal Server Error">
    <cfscript>
        Variables.sessionKeyRequest = REReplace(Variables.sessionIDRequest.FileContent, "^\s*[[:word:]]*\s*\(\s*","");
        Variables.sessionKeyRequest = REReplace(Variables.sessionKeyRequest, "\s*\)\s*$", "");
        Variables.sessionInfo = DeserializeJSON(Variables.sessionKeyRequest);
        Session.searchAccountSessionKey = Variables.sessionInfo.sid;
    </cfscript>
    <cfhttp url="http://www.easports.com/iframe/fut/p/ut/game/fifa14/phishing/validate" method="POST" result="phishingKeyRequest">
        <cfhttpparam type="header" name="Accept" value="application/json" />
        <cfhttpparam type="header" name="Accept-Language" value="en-US, en;q=0.5" />
        <cfhttpparam type="header" name="Connection" value="keep-alive" />
        <cfhttpparam type="header" name="Content-Length" value="39" />
        <cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded" />
        <cfhttpparam type="header" name="Cookie" value="#Session.searchAccountCookie#" />
        <cfhttpparam type="header" name="Easw-Session-Data-Nucleus-ID" value="1000215983198" />
        <cfhttpparam type="header" name="Host" value="www.easports.com" />
        <cfhttpparam type="header" name="Pragma" value="no-cache" />
        <cfhttpparam type="header" name="Referer" value="http://www.easports.com/iframe/fut/?baseShowoffUrl=http%3A%2F%2Fwww.easports.com%2Fuk%2Ffifa%2Ffootball-club%2Fultimate-team%2Fshow-off&guest_app_uri=http%3A%2F%2Fwww.easports.com%2Fuk%2Ffifa%2Ffootball-club%2Fultimate-team&locale=en_GB">
        <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-UT-Embed-Error" value="true" />
        <cfhttpparam type="header" name="X-UT-Route" value="https://utas.fut.ea.com:443" />
        <cfhttpparam type="header" name="X-Requested-With" value="XMLHttpRequest" />
        <cfhttpparam type="header" name="X-UT-SID" value="#Session.searchAccountSessionKey#" />
        <cfhttpparam type="formField" name="answer" value="#Variables.secretAnswer#">
    </cfhttp>
<cfelse>
    <cfset Variables.doReload = 1 />
</cfif>

<cfif StructKeyExists(Variables,"phishingKeyRequest") AND StructKeyExists(Variables.phishingKeyRequest.ResponseHeader,"Set-Cookie")>    
    <cfscript>
        Variables.returnedCookies = phishingKeyRequest.ResponseHeader["Set-Cookie"];
        Session.searchAccountPhishingKey = ListFirst(Variables.returnedCookies,";");
        if (StructKeyExists(Variables,"easfcWebSession")) {
            Variables.cookieStr = Variables.easfcWebSession & "; " & Variables.hl & "; " & Variables.xsrfToken & "; device=not_mobile; " & Session.searchAccountPhishingKey;
            Session.searchAccountLoggedIn = 1;
            Session.searchAccountLoginAttempts = 0;
        } else {
            Variables.doReload = 1;
        }
    </cfscript>
<cfelse>
    <cfset Variables.doReload = 1 />
</cfif>

<!--- IF RELOAD PAGE FLAG SET TO TRUE RELOAD --->
<cfif Variables.doReload EQ 1>

    <!--- RELOAD PAGE --->
    <script>
        location.reload();
    </script>

</cfif>

我遇到的问题是,搜索响应需要几百毫秒才能返回,这导致我错过了相当多的项目(因为有一些API可以更快地返回这些数据)。

有什么办法可以增加我收到回复的时间吗?在我的代码或CFHTTP的替代函数中,有什么我可以修改的吗?或者甚至还有另一种语言,如Ruby或C#,我可能会更好地编写API,因为它可以更快地执行这种功能,因为在一天结束时,速度是最重要的因素。

谢谢您的任何建议。

EN

回答 1

Stack Overflow用户

发布于 2013-12-21 21:49:43

CFHTTP将打开一个连接,发出请求,然后关闭连接。如果我读对了,您的logMeIn.cfm正在发出14个http请求。建立每个连接需要花费相当长的时间。

我想你有两个选择:

提前登录

是否可以在线程中或使用CF调度程序定期运行logMeIn.cfm,并将searchAccount40SessionKey值保留在应用程序范围内?您的代码可以发出请求并查看会话ID是否仍然良好。如果是的话,就别管它了。如果没有,请通过登录过程。如果您的站点支持许多用户,这可能不是一种可伸缩的方法。如果它只适用于少数人,它可能会起作用

使用不同的HTTP库。

CF附带了HTTPClient (我认为,现在只是下载检查)。具有执行连接管理的能力。这样,您应该能够在所有请求中保持一个连接。这将意味着重写您的大部分代码,但您应该会看到一个显著的速度增长。您也可以简化一些事情,因为HTTPClient可以对cookie/location进行一些管理,然后再进行重定向。

看看这个答案:理解ColdFusion中的持久HTTP连接

如果您还没有这样做,请通过Fiddler代理您的请求,这样您就可以看到客户机/服务器是如何交互的。要使用Fiddler,请安装它,启动它,然后修改CFHTTP调用以使用proxyServer=localhost和proxyPort=8888。然后,您将看到所列出的HTTP调用。在这种工作中它是无价的。它还允许您将请求拖到composer选项卡中,对其进行编辑,然后重新发送,这比重写代码要快得多,只是为了尝试一下。

更新

@CPB07 07在评论中增加了一些细节。会话ID已经在会话中缓存和保存,这意味着第一个建议已经实现。另一个信息是,search.cfm每隔335‘s就被调用一次,这就是需要优化的地方。有鉴于此,我能想到的最好的改进就是将search.cfm中的CFHTTP调用切换到使用HTTPClient。CF10附带了HTTPComponents‘HTTPClient的最新版本,因此此页第2.3节中列出的代码应该大致符合您的要求。第2.3.1节中的示例使用了一个HTTPContext,它有一个getCookieStore()方法,它有一个addCookie()方法,它允许您设置会话cookie,并在每个请求中使用它。粗略地说,代码中try块之外的所有内容都可以运行一次,对象可以存储在会话中,然后每次都可以运行实际的请求/连接打开。

另一件事情是,首先您是如何执行代码的。您说您不太熟悉线程,我猜这意味着您正在使用调度程序或AJAX进行轮询。通过在线程中运行轮询代码,您可能会获得更一致的结果,但这会增加更多的复杂性。

更新2

使用Fiddler访问search.cfm中的URL,查看statistics选项卡,两个关键数字是:

  • TCP/IP连接: 5ms
  • HTTPS握手:186

如果您保持连接打开,则可以平均节省每次请求所需的时间。保持活动只为一定数量的请求保持连接打开,因此您确实必须定期重新连接,但考虑到您每隔335 in发出请求,在连接时间内花费200 in的时间似乎很高。浏览器是否每335 Is请求搜索1.cfm?如果是这样的话,您将付出双倍的代价,因为浏览器连接到您的服务器,那么就必须连接到外部服务器。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20719219

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档