当我尝试从我的融合表中获取数据时,我收到了我的请求字符串,如
<! DOCTYPE HTML Public "-//w3c//dtd html final// EN>
<HTML>
<Head>
<style>
a:link {font:....}
a:visited {font:......}
</style>
<meta HTTP-EQUIV="content-type" content="text-html; charset= window....">
与我从java或c#API收到的不一样 我的C代码就是那样
typedef struct pageInfo_t {
char *data;
int len;
} pageInfo_t;
static size_t HTTPData(void *buffer, size_t size, size_t nmemb, void *userData) {
int len = size * nmemb;
pageInfo_t *page = (pageInfo_t *)userData;
if (buffer && page->data && (page->len + len < (16 * 1024)) ) {
memcpy(&page->data[page->len], buffer, len);
page->len += len;
}
return len;
}
const char urlDataT[]="http://www.google.com/fusiontables/api/query?sql=select * from 3333333";
jstring Java_com_AnalyticToolC_AnalyticToolActivity_JNIGetToken( JNIEnv* env,jobject entryObject)
{
pageInfo_t page;
CURL *curl;
CURLcode res;
char *buffer;
page.data = (char *)malloc(16 * 1024);
page.len = 0;
if (page.data)
memset(page.data, 32, 16 * 1024);
buffer = (char *)malloc(1024);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, urlDataT);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HTTPData);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &page);
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
if(res == 0) {
if (buffer) {
page.data[page.len < 256 ? page.len : 256] = '\0';
sprintf(buffer, "pagedata(%d): %s. done.\n", page.len, page.data);
return (*env)->NewStringUTF(env, buffer);
}
}
sprintf(buffer, "Result %d", res);
return (*env)->NewStringUTF(env, buffer);
} else {
return (*env)->NewStringUTF(env, "Unable to init cURL");
}
}
我应该怎么做才能收到包含表格数据的字符串
答案 0 :(得分:0)
您需要对您的请求进行网址编码。 E.g。
$ curl "http://www.google.com/fusiontables/api/query?sql=select+*+from+3333333"