ContentProxy

Most browsers don’t allow XMLHttpRequest to retrieve data from domains other than the domain where the script was fetched from, as shown in the diagram below.

ContentProxy1

Because of this security restriction, Pageflakes provides a content proxy server that can be used to fetch data from other domains. To do this, the flake makes a request to the proxy server. The proxy server then retrieves the content and returns it to the browser, as shown below.

ContentProxy1

The Content Proxy provides several methods:


ContentProxy.GetUrl(url, F(this, callbackFunction))
ContentProxy.FormPost(url, values, F(this, callbackFunction))
ContentProxy.UploadString(url, "content as string which is POSTed", F(this, callbackFunction));

If the call is successful, the content proxy invokes a function that was passed to it as callback.

The ContentProxy is set to cache any retrieved data for 10 minutes (GET calls only). Successive calls with the same parameters use the cached data rather than re-fetching the data from the remote server. This action optimizes flake performance. However, if updated data is required before the 15 minute interval, the GetURL or FormPost methods cannot be used.

Non-cached results can be retrieved using ContentProxy.getUrlNonCached(). The parameters are the same as ContentProxy.GetUrl().

HTTP GET Example

This code demonstrates the use of HTTP GET with the ContentProxy object:

ContentProxy.GetUrl("http://xml.example.com/", F(this, callback), onerror);

function callback(result)
{
// result is a string that can be used as needed
}
function onerror(exception)
{
}

HTTP POST Example

This example demonstrates how to pass POST parameters when using the ContentProxy object.

POSTData = {};
POSTData.parameter1 = "Some data";
POSTData.parameter2 = "Some more data";
ContentProxy.FormPost(url, POSTData, F(this, callback), onerror);
Alternatively, the following is also acceptable:
ContentProxy.FormPost(url, { parameter1 : “Some data”, parameter2 : “some more data” }, F(this, callback));

ContentProxyResponse

The ContentProxyResponse object is used by several of the ContentProxy functions to return headers and cookies, in addition to the returned content. This object has three properties:

Property Description
Content A string containing the content returned by the HTTP operation.
Header An array of objects, each representing an HTTP header. Each object has two properties: "Key" and "Value". "Key" is a string representing the name of the header, and “Value” is a string representing the value of the header.
Cookie An array of objects, each representing a cookie. Each object has two properties: "Key" and "Value". "Key" is a string representing the name of the cookie, and "Value" is a string representing the value of the cookie.


Header = [ { Key: “Content-Type” , Value: “foo”}, {Content-Length, “bar”] ]

GetUrl

Method signature

ContentProxy.GetUrl(url,succeededCallback, failedCallback)

Input Parameters

url

The URL of the target location.

 

succeededCallback

The function to invoked when the operation succeeds

 

failedCallback

The function to be invoked if the operation fails

Callback Parameter

Content of HTTP response as string.

Notes

The response is cached for 10 minutes.

GetUrl1

Method signature ContentProxy.GetUrl1(url, cacheDurationInMinutes, succeededCallback, failedCallback)
Input Parameters url The URL of the target location.
  cacheDurationInMinutes Specifies how long the response is cached on the server.
  succeededCallback The function that is invoked when the operation succeeds.
  failedCallback The function that is invoked if the operation fails.
Callback Parameter Content of the HTTP response as string.
Note The response is cached for the specified duration.

GetUrl2

Method signature ContentProxy.GetUrl2(url, headers, succeededCallback, failedCallback)
Input Parameters url The URL of the target location.
  headers

An array of headers used to create the request object.

Each header object is a one-dimensional array having two elements. The first element is the name of the header and the second one is its value.

For example:

[ ["Content-Type","text/plain"], ["X-MyHeader","foo"] ]

  succeededCallback The function that is invoked when the operation succeeds.
  failedCallback The function that is invoked if the operation fails.
Callback Parameter Content of HTTP response as string.
Note The response is cached for 10 minutes.

GetUrl3

Method signature ContentProxy.GetUrl3(url, headers, cookies, succeededCallback, failedCallback)
Input Parameters url The URL of the target location.
  headers An array of headers used to create the request object.

Each header object is a one-dimensional array having two element. The first element is the name of the header and the second one is its value.

For example:

[ ["Content-Type","text/plain"], ["X-MyHeader","foo"] ]

  cookies An array of cookies used to create the request object.

Each cookie object a one-dimensional array having two elements. The first element is name of the cookie and the second one is its value.

For example:

[ ["session-id","1234"], ["other-cookie","foo"] ]

  succeededCallback The function that is invoked when the operation succeeds.
  failedCallback The function that is invoked if the operation fails.
Callback Parameter A ContentProxyResponse object.
Note The response is cached for 10 minutes.

GetUrlNonCached

Method signature ContentProxy.GetUrlNonCached(url,succeededCallback,
failedCallback)
Input Parameters url The URL of the target location.
  succeededCallback The function that is invoked when the operation succeeds
  failedCallback The function that is invoked if the operation fails
Callback Parameter Content of HTTP response as string
Note The response will not be cached.

GetUrlNonCached2

Method signature ContentProxy.GetUrlNonCached2(url, headers, cookies, succeededCallback, failedCallback)
Input Parameters url The URL of the target location.
  headers An array of headers used to create the request object.

Each header object is a one-dimensional array having two elements. The first element is the name of the header and the second one is its value.

For example:

[ [“Content-Type”,“text/plain”], [“X-MyHeader”,“foo”] ]

  cookies An array of cookies used to create the request object.

Each cookie object a one-dimensional array having two
elements. The first element is name of the cookie and the second one is its
value.

For example:

[ [“session-id”,“1234”], [“other-cookie”,“foo”] ]

  succeededCallback The function that is invoked when the operation succeeds.
  failedCallback The function that is invoked if the operation fails.
Callback Parameter A ContentProxyResponse object.
Note The response is not cached.

FormPost

Method signature ContentProxy.FormPost(url, parameters, succeededCallback, failedCallback)
Input Parameters url The URL of the target location.
  parameters Parameters that are passed with a given URL. The
parameters object basically is a dictionary which contains the parameters
name and value as key-value pair.
  succeededCallback The function that is invoked when the operation succeeds.
  failedCallback The function that is invoked if the operation fails.
Callback Parameter The content of the HTTP response as a string.
Note FormPost method performs an HTTP POST operation.

FormPost2

Method signature ContentProxy.FormPost2(url, parameters, headers, succeededCallback, failedCallback)
Input Parameters url The URL of the target location.
  parameters Parameters that are passed with the given URL. The parameters object is a dictionary which contains the parameters name and value as a key-value pair.
  headers

An array of headers used to create the request object.

Each header object is a one-dimensional array with two elements. The first element is the name of the header and the second is its value.

For example:

[ ["Content-Type","text/plain"], ["X-MyHeader","foo"] ]

  succeededCallback The function that is invoked when the operation succeeds.
  failedCallback The function that is invoked if the operation fails.
Callback Parameter The content of the HTTP response as a string.
Note FormPost2 method performs an HTTP POST operation.

FormPost3

Method signature ContentProxy.FormPost2(url, parameters, headers, cookies, succeededCallback, failedCallback)
Input Parameters url The URL of the target location.
  parameters The parameters passed to the given url. The parameters object basically is a dictionary which contains the parameter’s name and value as a key-value pair.
  headers

An array of headers used to create the request object.

Each header object is a one-dimensional array having two elements. The first element is the name of the header and the second one is its value.

For example:

[ ["Content-Type","text/plain"], ["X-MyHeader","uoo"] ]

  cookies An array of cookies used to create the request object.

Each cookie object is a one-dimensional array having two elements. The first element is the name of the cookie and the second one is its value.

For example:

[ [“session_id”,“abc123”], [“cart_status”,“foobar”] ]

  succeededCallback The function that is invoked when the operation succeeds.
  failedCallback The function that is invoked if the operation fails.
Callback Parameter Content of HTTP response as string.
Note FormPost2 method performs an HTTP POST operation.

UploadString

Method signature ContentProxy.UploadString(url, requestData, succeededCallback, failedCallback)
Input Parameters url The URL of the target location.
  requestData Data to be POSTed
  succeededCallback The function that is invoked when the operation succeeds.
  failedCallback The function that is invoked if the operation fails.
Callback Parameter Content of HTTP response as string.
Note UploadString method performs HTTP POST operation and uploads the raw string to the specified URL. Useful for making SOAP calls.

UploadString2

Method signature ContentProxy.UploadString2(url, headers,
requestData, succeededCallback, failedCallback)
Input Parameters url The URL of the target location.
  headers An array of headers used to create the request object

Each header object is a one-dimensional array with two elements. The first element is the name of the header and the second one is its value.

For example:

[ ["Content-Type","text/plain"], ["X-MyHeader","foo"] ]

  requestData Data to be POSTed
  succeededCallback The function that is invoked when the operation succeeds.
  failedCallback The function that is invoked if the operation fails.
Callback Parameter Content of HTTP response as string.
Note UploadString2 performs an HTTP POST operation.