cancel
Showing results for 
Search instead for 
Did you mean: 
cancel

gadget.io.makerequest GET with Paramaters fails with 403

1425
Views
0
Helpful
1
Comments
This document was generated from CDN thread

Created by: David Womer on 13-04-2012 05:03:41 PM
Team,
 
I'm trying to use the gadget.io.makerequest method to retrieve JSON data within my gadget.  I have this working if I do not pass any paramters to my service, however, if I add ?parameter=value  I get a 403 error. I have been able to succesfully call this service with paramters direclty form the web browser as well as an http client.  
 
Here's the code I'm using:
 

function makeJSONRequest() {
    var params = {};
    params[gadgets.io.RequestParameters.CONTENT_TYPE] = "text/html";
    params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.GET;
    var url = "http://app02:8080/soap.php?accountNumber=11111";
    gadgets.io.makeRequest(url, response, params);
};

 
 
Here's what I see returned from the request:
<ol class="properties properties-tree monospace" style="box-sizing: border-box; outline-style: none; outline-width: initial; outline-color: initial; font-size: 11px !important; font-family: Menlo, monospace; padding-top: 0px; padding-right: 6px; padding-bottom: 2px; padding-left: 16px; list-style-type: none; list-style-position: initial; list-style-image: initial; min-height: 18px; display: block; -webkit-text-size-adjust: none; line-height: normal; margin: 0px;">
<li class="parent expanded selected" style="box-sizing: border-box; margin-left: 1px; white-space: nowrap; text-overflow: ellipsis; overflow-x: hidden; overflow-y: hidden; -webkit-user-select: text; cursor: auto;">http://app02:8080/soap.php?accountNumber=11111: {,…}<ol class="children expanded" style="box-sizing: border-box; display: block; -webkit-padding-start: 12px; list-style-type: none; list-style-position: initial; list-style-image: initial; margin: 0px;">
<li style="box-sizing: border-box; margin-left: 12px; white-space: nowrap; text-overflow: ellipsis; overflow-x: hidden; overflow-y: hidden; -webkit-user-select: text; cursor: auto;">DataHash: "csqkfhq4gui851dd113bdce9fg"</li>
<li style="box-sizing: border-box; margin-left: 12px; white-space: nowrap; text-overflow: ellipsis; overflow-x: hidden; overflow-y: hidden; -webkit-user-select: text; cursor: auto;">body: "<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">↵<html><head>↵<title>403 Forbidden</title>↵</head><body>↵<h1>Forbidden</h1>↵<p>You don't have permission to access /soap.php↵on this server.</p>↵</body></html>↵"</li>
<li style="box-sizing: border-box; margin-left: 12px; white-space: nowrap; text-overflow: ellipsis; overflow-x: hidden; overflow-y: hidden; -webkit-user-select: text; cursor: auto;">rc: 403</li>
</ol></li>
</ol>

Subject: RE: gadget.io.makerequest GET with Paramaters fails with 403
Replied by: David Lender on 16-04-2012 10:44:17 AM
It appears the error is coming from your web server not Finesse.  I suggest you try content-type application/xml rather than text/xml.

Subject: RE: gadget.io.makerequest GET with Paramaters fails with 403
Replied by: David Womer on 16-04-2012 11:28:35 AM
Hi David,

This appears to be working today.  I'm guessing it was some kind of cacheing issue but I'm not sure where the problem was.  I tried a number of different content types, restarted the web server, and restarted by dev environment but kept getting the same result.  Does Finesse cache the widget code?

The strange part about this is that it would only fail when I passed parameters in the URL string.  Otherwise it would work fine.  You can see the request on the web server side:

172.35.1.67 - - [13/Apr/2012:14:54:00 -0500] "GET /soap.php?accountNumber=11111 HTTP/1.1" 403 210
127.0.0.1 - - [13/Apr/2012:15:07:26 -0500] "GET /soap.php?accountNumber=11111 HTTP/1.1" 200 193

the 172.35.1.67 address is Finesse.  I was just about to turn up some additional logging, but it starting working. 

-Dave

Subject: RE: gadget.io.makerequest GET with Paramaters fails with 403
Replied by: David Lender on 16-04-2012 12:01:26 PM
Does Finesse cache the widget code?


 
No cache.  You should be able to just logout the agent(s) and log back in again and the latest gadget xml is fetched.

Subject: RE: gadget.io.makerequest GET with Paramaters fails with 403
Replied by: David Womer on 16-04-2012 01:53:25 PM
David - Thanks for the response.  I think I figured out where the cacheing is occurring.  gadgets.io.makerequest() caches web calls be default, so you need to disable cacheing when the request is made as outlined in this document:

http://code.google.com/p/opensocial-resources/wiki/GadgetsMakeRequest

The following code is working for me now:


function makeJSONRequest(webServiceURL) {

    var refreshInterval = 0; // no cache
    var ts = new Date().getTime();
    var sep = "?";
    if (refreshInterval && refreshInterval > 0) {
        ts = Math.floor(ts / (refreshInterval * 1000));
    }
    if (webServiceURL.indexOf("?") > -1) {
        sep = "&";
    }
    webServiceURL = [ webServiceURL, sep, "nocache=", ts ].join("");

    var params = {};
    params[gadgets.io.RequestParameters.CONTENT_TYPE] = "text/html";
    params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.GET;
    gadgets.io.makeRequest(webServiceURL, response, params);
};
Comments

Hello,

Are You use it to conrtact with some API which remains basic auth? because It works for me when some server to which I want send request is without authorization but when I would like to send to Finesse API (remain basic auth) it show in logs that it remain authentication.

Content for Community-Ad