Skip to main content
Participant
June 4, 2009
Question

CFHTTP problem - is file-type extension required

  • June 4, 2009
  • 1 reply
  • 3992 views

Hello,

Running CF8 on Win2003/IIS. 

I have the following simple code to check a value from another server:

<cfhttp method="get" URL= "http://server.somewhere.com/websvc/util?a=doHTMLRequest&event=workgroupstat"   throwonerror="yes">

<cfset theContent = "#cfhttp.FileContent#">

<cfoutput>#theContent#</cfoutput>

I have also tried:

<cfhttp
  method="get"
  url="http://server.somewhere.com/websvc/util">  (with and without the ? after the word util)
  <cfhttpparam name="a" type="URL" value="doHTMLRequest">
  <cfhttpparam name="event" type="URL" value="workgroupstat">
</cfhttp>

The URL that is shown above returns nothing when using it within CFHTTP. If I change the URL to http://www.google.com or whatever I get the code of that page assigned to my theContent variable as expected 

From a browser, the URL used in the cfhttp function above works fine. The request returns a simple HTML file with the following code from which I need to pull the agents_available data:

<HTML><HEAD><TITLE>Agents Available</TITLE></HEAD><BODY><H2>workgroup:Chat</H2><H2>agents_available:1</H2><H2>agents_logged_in:1</H2></BODY></HTML>

I cannot understand why I can call any other page from the internet (and our network) and put it into my theContent variable but I can't call this one.  Could it be something in the structure of the URL??

I'm thinking that the CFHTTP function cannot properly format the request without the file-type extension.

Any ideas are appreciate.  Regards, Jerry

This topic has been closed for replies.

1 reply

ilssac
Inspiring
June 4, 2009

The two steps I would use to start analysing this problem.

1) Change the <cfhttp...> to use the throwonerror="no" AND redirect="no" parameters and then use <cfdump var="#cfhttp#"> afterword.

This should show you exactly what the server is returning to you for these request you are making, not just the content.

2) Do the request in a browser such as FireFox with the HTTP Headers plugin and look at all the content that is being sent between the browser and the server.  Look closely at any post, get and cookie headers that are being sent and then povide matching content in your <cfhttp...> tag.

Participant
June 4, 2009

Hi Ian,

I tried your suggestions.  Used Firefox with FireBug and LiveHTTP Headers and nothing appears out of the ordinary except the Content-Length which is always 0.  It's not being redirected.  The response is 200 OK.

i.e.:

cfhttp.errorDetail: 
cfhttp.text:  YES
cfhttp.statusCode  200 OK
cfhttp.MIMEType  Unable to determine MIME type of file.
cfhttp.header  HTTP/1.1 200 OK Set-Cookie: JSESSIONID=88760F22E9FA8717DE807D6F1F758E9A; Path=/websvc Date: Thu, 04 Jun 2009 17:04:37 GMT Content-Length: 0 Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET

But when the URL is called directly from a browser the Content-Length is not 0.  It is 148 bytes.

I'm using:

<cfset Mokrynski.PageName = "_">

<cfsetting showdebugoutput="no">

<!---cfhttp   method="get"   url="http://server.somewhere.com/websvc/util">;  

<cfhttpparam name="a" type="URL" value="doHTMLRequest">  

<cfhttpparam name="event" type="URL" value="workgroupstat">

</cfhttp--->

<cfhttp   method="get"   url="http://server.somewhere.com/websvc/util?a=doHTMLRequest&event=workgroupstat" />

<cfset agentCount = (cfhttp.fileContent)>

<cfoutput>#agentCount#</cfoutput>

<cfoutput> <p>cfhttp.errorDetail:  #cfhttp.errorDetail#</p>

<p>cfhttp.text:  #cfhttp.text#</p>

<p>cfhttp.statusCode  #cfhttp.statusCode#</p>

<p>cfhttp.MIMEType  #cfhttp.MIMEType#</p>

<p>cfhttp.header  #cfhttp.header#</p>

</cfoutput>

Note that there are two methods I've used - 1 used commentd out in this code.  If i change the url in the cfhttp function to ANYTHING else I get the expected result - goog.com, our site, cnn.com, whomever but not from this URL which clearly works from a browser.

Thanks, Jerry

Inspiring
June 4, 2009

Is it possible that the page at http://server.somewhere.com/websvc/util is user-agent aware and is treating requests from a web browser differently from requests from CFHTTP?  You might try providing a value for the useragent attribute of CFHTTP to mimic IE or Firefox's user agent string.