0
當我嘗試從我的融合表中獲取數據,我從我的請求字符串收到類似捲曲帶桌子融合
<! 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");
}
}
我應該怎麼辦收到的字符串包含表數據
我解決這個問題只需添加這兩種選項進行卷曲之前: curl_easy_setopt(捲曲,CURLOPT_HTTPGET,1L); struct curl_slist * headers = NULL; headers = curl_slist_append(headers,「Content-Type:application/atom + xml」); curl_easy_setopt(curl,CURLOPT_HTTPHEADER,headers); – Serngawy 2012-03-29 15:49:48
對不起,沒有意識到java有一個curl庫。 – 2012-03-29 20:53:24