• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Passing data to another server as variables

Enthusiast ,
Nov 12, 2009 Nov 12, 2009

Copy link to clipboard

Copied

I need to pass some variables back to a 3rd party server after it makes a request which I initially validate.

right now I just put the result into the web browser, however I want to be able to feed the variables in a format that appears to the 3rd party server as if the info was passed back as url variables, a=123,b=456 etc

Can somebody enlighten me on how to do this?

Thanks

Mark

TOPICS
Advanced techniques

Views

1.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 14, 2009 Nov 14, 2009

Copy link to clipboard

Copied

Check out the cfhttp and cfhttpparam tags, basically like posting a form without pressing submit (just runs when page runs).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 14, 2009 Nov 14, 2009

Copy link to clipboard

Copied

I don't think that this will do it, I've used this in another part of the site to integrate with PayPal

CFHTTP enabled me to post to another server, but what I need to do is have a server retrieve information from MY server when it hits a particular URL

Thanks

Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 14, 2009 Nov 14, 2009

Copy link to clipboard

Copied

Write a web service.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 14, 2009 Nov 14, 2009

Copy link to clipboard

Copied

Are you aware you can send and receive data with cfhttp. You might like to have a play around with the code below...

<!--- INDEX.CFM --->

<!--- Get password protected content --->
<cfhttp
        name="myQuery"
        url="localhost:8500/test/source.cfm"
        method="get"
        firstrowasheaders="no"
        columns="firstName,lastName">
    <cfhttpparam type="url" name="password" value="letmein">
</cfhttp>

<!--- Output content --->
<cfif myQuery.RecordCount NEQ 0>
    <cfdump var="#myQuery#">
    <cfelse>
    <p>You don't have permission to access this content</p>
</cfif>

<!--- SOURCE.CFM --->

<!--- Simulate a database query --->
<cfset myQuery = QueryNew("firstName, lastName", "Varchar, Varchar") />
<cfset newRow = QueryAddRow(myQuery, 2) />
<cfset temp = QuerySetCell(myQuery, "firstName", "Alan", 1) />
<cfset temp = QuerySetCell(myQuery, "lastName", "Jones", 1) />
<cfset temp = QuerySetCell(myQuery, "firstName", "Bob", 2) />
<cfset temp = QuerySetCell(myQuery, "lastName", "Jane", 2) />

<!--- Protect content --->
<cfif StructKeyExists(url, "password") AND url.password EQ "letmein">
<!--- Output query - Don't indent cfoutput tags! --->
<cfoutput query="myQuery">
    #firstName#,#lastName#
</cfoutput>
</cfif>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 15, 2009 Nov 15, 2009

Copy link to clipboard

Copied

CFHTTP enabled me to post to another server, but what I need to do is have a server retrieve information from MY server when it hits a particular URL

Chris has pointed you in the right direction. The cfhttp tag can do it both ways. What you used in posting was <cfhttp method="post">. What someone else would use to get data from your server is <cfhttp method="get">, or the equivalent code if their language is different from Coldfusion.

And what do you have to do on the requested page? Anything you want. As you have already mentioned, something like this will do:

a=1; b=2

In any case, it would be nice to let the client know how you will be presenting the data. Then he will know how to fetch it.

The query-string, that is, a URL variable, is generally for sending data, not for receiving. However, if you insist that the client should get URL variables, then he could click on a link on your site in which you append URL variables. Alternatively, you could use cflocation to redirect him to a URL to which you have appended URL variables.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 15, 2009 Nov 15, 2009

Copy link to clipboard

Copied

I had used CFHTTP to GET data but never post it back, it looks like I have to do more research on the POST part.

Let me clarify the actual process

a) The 3rd party server makes a server side request to our server for a 'key;

b) Our server validates variables within the received post, user ID, password etc, and validates

c) If validated correctly, a key is generated and passed back to the 3rd party server

It's all coded and working, but at the moment I display the key in HTML, I put <cfsetting enablecfoutputonly="true"> in there to stop any white space, but for some unknown reason it dumps a ton of empty lines into the source.

So the mission was to have the final output which is passed to the 3rd party in a format that allowed it to read the variable

so instead of display the key in the HTML as ABCDEFGH, it would receive key=ABCDEFGH

In the future I may return more variables, so I need to accomodate for this

Do you think CFHTTP is still the way to go?

Thanks

Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 15, 2009 Nov 15, 2009

Copy link to clipboard

Copied

Do you think CFHTTP is still the way to go?

If the other servers are using CFML, probably yes. If not, Google 'coldfusion web services'. The advantage of using a web service is that it can be transformed into any language. If you do decide to go with CFHTTP, the following should set you in the right direction.

<!--- INDEX.CFM --->

<!--- Get password protected file content (key) --->
<cfhttp url="localhost:8500/test/source.cfm" method="get">
    <cfhttpparam type="url" name="password" value="letmein">
</cfhttp>

<!--- Output returned file content (key) --->
<cfoutput>#cfhttp.FileContent#</cfoutput>

<!--- Optional - Set variable (any scope) from returned file content (key) --->
<cfset session.key = cfhttp.FileContent />

<!--- SOURCE.CFM --->

<!--- Protect file content (key) --->
<cfif StructKeyExists(url, "password") AND url.password EQ "letmein">
    <!--- Create file content (key) --->
    <cfset variables.key = CreateUUID()>
    <!--- Output file content (key) --->
    <cfoutput>#variables.key#</cfoutput>
</cfif>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 15, 2009 Nov 15, 2009

Copy link to clipboard

Copied

In the future I may return more variables, so I need to accomodate for this

Do you think CFHTTP is still the way to go?

CFHTTP is OK, but I would now lean more towards Dan's idea, a web service. This assumes of course that you will have no trouble convincing your clients to convert.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 16, 2009 Nov 16, 2009

Copy link to clipboard

Copied

I won't be able to ask the 3rd parties to convert their systems, so I'm going to have to leave them to their own devices on that side of things, .NET, PHP whatever they decide to use to make the post to our server.

I'm currently outputting the info in HTML just literally using <CFOUTPUT>#key#</CFOUTPUT> but as I mentioned earlier it's putting a ton of line breaks above it. I've tried all the options to stop it displaying white space and it appears to keep ignoring them

The part I need to resolve is the final stage, delivering the data to them when they hit our server with a request, preferably as a variable, I looked at CFHTTP but the documentation suggested that a URL was REQUIRED so I'm not sure how it could be used to feed data back to a requesting url?

I'm a little confused on this one

Thanks

Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 16, 2009 Nov 16, 2009

Copy link to clipboard

Copied

Use

<cfcontent reset="yes" type="text/xml; charset=UTF-8" /><CFOUTPUT><key>#key#</key></CFOUTPUT>

to get rid of the whitespace and present your data in XML.

Congratulations, you have just written your first webservice

Message was edited by: Jochem van Dieten to unbreak what the stupid HTML conversion macro's that Jive refuses to document broke

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 16, 2009 Nov 16, 2009

Copy link to clipboard

Copied

the problem is that I can't get rid of that darn white space!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 16, 2009 Nov 16, 2009

Copy link to clipboard

Copied

I made the code that these forums broke readable. Use the cfcontent tag to strip all the whitespace.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 16, 2009 Nov 16, 2009

Copy link to clipboard

Copied

I want to strip out white space BEFORE it's served out to the 3rd party so they don't have to worry about it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 16, 2009 Nov 16, 2009

Copy link to clipboard

Copied

Did you try the code?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 16, 2009 Nov 16, 2009

Copy link to clipboard

Copied

ahh, I did not notice the code, I'll try it later, as I have to take care of a time sensitive issue right now

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 16, 2009 Nov 16, 2009

Copy link to clipboard

Copied

The part I need to resolve is the final stage, delivering the data to them when they hit our server with a request, preferably as a variable, I looked at CFHTTP but the documentation suggested that a URL was REQUIRED so I'm not sure how it could be used to feed data back to a requesting url?

I'm a little confused on this one

I suspect it's easier than you think. Suppose you put the line

key=12kg7tsy34

in the page getKey.cfm of your site. Then a client on Coldfusion can do the following:

1) Run a page containing  <cfhttp url="http://yourDomain/getKey.cfm" method="get">

2) Parse cfhttp.filecontent to obtain the key.

Other languages have their own way of doing the same thing.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 16, 2009 Nov 16, 2009

Copy link to clipboard

Copied

that method did cross my mind, but I thought that perhaps there was a more 'techincal' way of performing this, especially if I start to get into displaying more than one variable

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 16, 2009 Nov 16, 2009

Copy link to clipboard

Copied

LATEST
I thought that perhaps there was a more 'techincal' way of performing this, especially if I start to get into displaying more than one variable

Yes, a web service. Use it to return the client an XML containing something like

<keys>
<clientKey>abc123</clientKey>
<orderKey>def345</orderKey>
</keys>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation