I’m developing a Gmail Contextual Gadget and now I’m faced with a Post Http communication problem. I don’t have any problem with get request, here’s is my get request code:
var mydata = { id: 10, name: 'sample1'};
var params = {};
var url = "https://myserver/handler/sample.ashx" + "?" + gadgets.io.encodeValues(mydata);
params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
params[gadgets.io.RequestParameters.AUTHORIZATION]=gadgets.io.AuthorizationType.SIGNED;
params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.GET;
gadgets.io.makerequest(url,callback,params);
But when I need to make post request, I have a problem to getting mydata in server side. I checked all variable in request.Params, request.QueryString, request.Form. There is nothing!
var mydata = { id: 10, name: 'sample1'};
var params = {};
var url = "https://myserver/handler/sample.ashx";
params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
params[gadgets.io.RequestParameters.AUTHORIZATION]=gadgets.io.AuthorizationType.SIGNED;
params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
params[gadgets.io.RequestParameters.POST_DATA] = mydata;
gadgets.io.makerequest(url,callback,params);
What is my problem?
use gadgets.io.encodeValues to set POST_DATA
params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
Or to isolate your data use this pattern:
params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues({
Gadget_Post_DATA: gadgets.json.stringify(mydata)
});;