I am doing a system that imports live data from Fusion tables.
I am using C# in Unity3D so, I don’t have the WebRequest from .NET framework.
However, Unity3D has WWW and WWWForm and I am trying to use those to query Fusion Tables.
I already have the Authentication Token but the SQL injection API is returning a 411 page requesting Content-Length.
I already added that to the headers, but still, no change…
Bellow i am posting the code for the Query Test, it assumes valid authentication in Fusion Tables
public string Execute(string query) {
string result;
var url_fusion_tables = "https://tables.googlelabs.com/api/query/?";
WWWForm postdata = new WWWForm();
System.Collections.Hashtable headers = postdata.headers;
headers["Method"] = "POST";
headers["Content-Type"] = "applicaton/x-www-form-urlencoded";
string header_token = string.Format("GoogleLogin auth = {0}", token);
headers["Authorization"] = header_token;
var sb = new StringBuilder();
sb.Append("sql=");
sb.Append(WWW.EscapeURL("SHOW TABLES"));
var data = Encoding.ASCII.GetBytes(sb.ToString());
headers["Content-Length"] = data.Length;
WWW reqClient = new WWW(url_fusion_tables, data, headers);
StartCoroutine(WaitForQuery(reqClient));
return null;
}
IEnumerator WaitForQuery(WWW www) {
yield return www;
if (www.error == null) {
//Debug.Log("Success");
Debug.Log("Received :: " + www.text);
} else {
Debug.Log("Query WWW error : "+ www.error);
}
}
Hope anyone can help.
Thanks in advance.
Due to Kathryn’s help i have edited the Execute function to the following:
public void Execute(string query) {
//in query : SHOW TABLES
var sql = string.Format("sql={0}", WWW.EscapeURL(query));
var url_fusion_tables = "https://www.google.com/fusiontables/api/query?";
WWWForm postdata = new WWWForm();
System.Collections.Hashtable headers = postdata.headers;
headers["AllowAutoRedirect"] = true;
headers["AllowWriteStreamBuffering "] = true;
headers["Method"] = "GET";
headers["Content-Type"] = "applicaton/x-www-form-urlencoded";
string header_token = string.Format("GoogleLogin auth = {0}", token);
headers["Authorization"] = header_token;
var data = Encoding.ASCII.GetBytes(sql);
headers["Content-Length"] = data.Length;
WWW reqClient = new WWW(url_fusion_tables, data, headers);
StartCoroutine(WaitForQuery(reqClient));
}
I’m still receiving 411 response
I finally resolved the problem…
As i said before, the 411 was returned because the token string i passed to the authentication header had a new line tag in it, so the server would interpret that as the end of the Header on the POST. Removing the \n at the end of the string results in a good request.
The next problem was due to a bad query, my mistake on putting the wrong Table ID.
Thanks Kathryn for your help.