【问题标题】:Posting credentials to cfhttp body using ColdFusion使用 ColdFusion 将凭据发布到 cfhttp 正文
【发布时间】:2019-03-14 15:10:03
【问题描述】:

我将传递一些凭据以及 __EVENTARGUMENT、__VIEWSTATE。但我无法在控制台或提琴手中看到变量和数据,我是否遗漏了什么。我尝试了 url、formfield 和 body,但没有成功。顺便说一句,我使用的是 ColdFusion 9。

<cfset authenticationRequestBody = "__LASTFOCUS=#LASTFOCUS#&__EVENTTARGET=#EVENTTARGET#&__EVENTARGUMENT=#EVENTARGUMENT#&__VIEWSTATE=#EncodeViewState#&__VIEWSTATEGENERATOR=#EncodeViewGenerator#&__EVENTVALIDATION=#EncodeEventValidation#&#encodeForURL(UNameString)#=#UserName#&#encodeForURL(PwdString)#=#encodeForURL(Password)#&#encodeForURL(ButtonString)#=Submit">


<cfset stsUrl = "https://somesite.com/yyy/login.aspx" >
<cfhttp url="#stsUrl#" method="post"  resolveurl="no"  >
    <cfhttpparam type="header" name="Accept" value="application/xhtml+xml,text/html">
    <cfhttpparam type="header" name="REFERER" value="#BaseUrl#" >
    <cfhttpparam type="header" name="Accept-Language" value="en-US">
    <cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded">
    <cfhttpparam type="header" name="Connection" value="keep-alive" >
    <cfhttpparam type="header" name="User-Agent" value="Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36" >
    <cfloop collection="#cookies#" item="i">
        <cfhttpparam type = "cookie" name="#i#" value="#cookies[i]#">
    </cfloop>
    <cfhttpparam type="body" name="PostData" value="#authenticationRequestBody#">


<cfoutput>
    <cfdump var="#GetHTTPRequestData()#">
</cfoutput>

这不是与配置相关的问题,因为我使用 SSL 测试服务器在站点检查了 JVM 版本和 TLS 版本。我在代码中缺少一些东西..

Coldfusion 11(更新 12) 虚拟机:1.8 TLS : 1.2

我本来可以到达登录屏幕的。即使在正文中传递了用户名和密码,它也不会验证。当我使用相同的凭据直接访问 URL 时,它会成功登录。

【问题讨论】:

  • 旁注,GetHTTPRequestData() 仅显示有关本地服务器或包含 cfhttp 代码的脚本的信息。它不显示有关对远程服务器的 cfhttp 调用的信息。
  • 当我转储 GetHTTPRequestData() 内容为空时,它确实显示了,方法:get(不知道为什么即使我在这里发帖时也会得到),协议和标头
  • 它显示的是关于 cfm 页面的信息 - 而不是 cfhttp 调用。
  • 是的,它只显示有关 cfm 的信息而不是呼叫
  • 是的,我的意思是它是一个很好的功能,但不适用于调试 cfhttp 调用 ;-) 它只能提供有关您所在页面的信息 - 而不是 cfhttp 调用的远程页面。 (只是提一下,以防您还没有意识到这一点)

标签: coldfusion coldfusion-9 cfhttp


【解决方案1】:

尝试做一个

<cfdump var="#cfhttp#">

<cfhttp url="#stsUrl#" method="post"  resolveurl="no" result="result" >  
   ...
</cfhttp>

<cfdump var="#result#">

【讨论】:

  • 试过了,但我无法将它传递给提琴手..在转储它状态代码说:200 OK mimetype:text/html and the entire HTML Filecontent
  • 您是否在循环解析内容中的 JSON 或 XML 响应?
  • No Iam not.. 我以名为 authenticationRequestBody 的 url 格式创建了凭据和其他数据,我试图将其传递到 cfhttpparam 的正文中。没有循环或解析 JSON/XML
  • &lt;cfhttp&gt; 是否有 method="post",如果合适的话?
  • 是的,它有 method="Post"
【解决方案2】:

问题不在于配置或兼容性版本。问题在于我们从一开始就传递的 cookie。当我们使用 cfhttp 浏览其他页面时,我们需要携带从过去获得的旧 cookie cfhttp 调用.. 同样在我的情况下,我需要在第一次调用中初始化 cookie.. 下面是两个调用的示例..

<cfhttp url='#BaseUrl#' method="get" redirect="no">
        <cfhttpparam type="header" name="Connection" value="keep-alive" >
        <cfhttpparam type="header" name="Cache-Control" value="no-cache">
        <cfhttpparam type="header" name="User-Agent" value="Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko">
        <cfhttpparam type="header" name="cookie" value="TestCookie=;" >
</cfhttp>

<cfhttp url="#stsUrl#" method="post"  redirect="no" resolveurl="yes" result="postResult" >
    <cfhttpparam type="header" name="REFERER" value="#BaseUrl#" >
    <cfhttpparam type="header" name="Cache-Control" value="no-cache">
    <cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded">
    <cfhttpparam type="header" name="Connection" value="keep-alive" >
    <cfhttpparam type="header" name="User-Agent" value="Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36" >

    <cfhttpparam type="header" name="cookie" value="TestCookie=;" encoded="yes">

    <cfloop collection="#CookieList#" item="i">
        <cfhttpparam type="header" name="cookie" value="#CookieList[i]#" encoded="yes">
    </cfloop>

    <cfhttpparam name="__LASTFOCUS"  value="" type="formfield">
    <cfhttpparam name="__EVENTTARGET"  value="" type="formfield">
    <cfhttpparam name="__EVENTARGUMENT"  value="" type="formfield">
    <cfhttpparam name="__VIEWSTATE"  value="#VIEWSTATE#" type="formfield">
    <cfhttpparam name="__VIEWSTATEGENERATOR"  value="#VIEWSTATEGENERATOR#" type="formfield">
    <cfhttpparam name="__EVENTVALIDATION"  value="#EVENTVALIDATION#" type="formfield">
    <cfhttpparam name="ctl00$MainContent$LoginCtrl$UserName"  value="#UserName#" type="formfield">
    <cfhttpparam name="ctl00$MainContent$LoginCtrl$Password"  value="#Password#" type="formfield">
    <cfhttpparam name="ctl00$MainContent$LoginCtrl$LoginButton"  value="Submit" type="formfield">
</cfhttp>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-19
    相关资源
    最近更新 更多