我寫了接收數據並存儲它們放在電子表格中的谷歌Apps的腳本,這樣的事情:HTTP GET/POST在Android上不與谷歌Apps腳本工作
https://script.google.com/macros/s/.../exec?t1=hi&t2=foo
的URL工作正常上瀏覽器和數據確實存儲。但是,當我嘗試從Android應用程序實現此功能時,它不起作用。我已經在AsyncTask中嘗試了HttpGet
和HttpPost
技術,但什麼也沒得到。這是HttpPost的代碼:
class sendData extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
String [] data = params[0].split("-");
postData(data[0],data[1]);
}
@Override
protected void onPostExecute(String result) {
// Update Ui here
}
public void postData(String l1, String l2) {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://script.google.com/macros/s/.../exec");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("test", l1));
nameValuePairs.add(new BasicNameValuePair("testt", l2));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
}
問題在哪裏?我已經將腳本和電子表格的隱私設置爲可供任何人訪問和編輯,並且仍然沒有任何迴應。我對web開發人員有點新,所以對我一無所知!
編輯:這裏是logcat。不知道這是否意味着什麼:
07-25 00:17:36.400: D/dalvikvm(31262): Late-enabling CheckJNI
07-25 00:17:36.415: I/dalvikvm(31262): Turning on JNI app bug workarounds for target SDK version 10...
07-25 00:17:36.420: E/jdwp(31262): Failed sending reply to debugger: Broken pipe
07-25 00:17:36.420: D/dalvikvm(31262): Debugger has detached; object registry had 1 entries
07-25 00:17:40.930: D/dalvikvm(31262): GC_CONCURRENT freed 220K, 7% free 12377K/13191K, paused 5ms+2ms, total 28ms
07-25 00:17:42.075: D/dalvikvm(31262): GC_CONCURRENT freed 314K, 7% free 12517K/13447K, paused 9ms+3ms, total 67ms
07-25 00:17:44.850: D/dalvikvm(31262): GC_CONCURRENT freed 341K, 7% free 12630K/13575K, paused 12ms+3ms, total 34ms
07-25 00:17:59.815: D/dalvikvm(31262): GC_CONCURRENT freed 435K, 8% free 12638K/13703K, paused 2ms+2ms, total 26ms
07-25 00:18:05.000: D/dalvikvm(31262): GC_CONCURRENT freed 380K, 8% free 12693K/13703K, paused 15ms+5ms, total 54ms
07-25 00:18:15.030: D/dalvikvm(31262): GC_CONCURRENT freed 366K, 8% free 12776K/13767K, paused 19ms+2ms, total 61ms
07-25 00:18:56.390: E/SpannableStringBuilder(31262): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
07-25 00:18:56.390: E/SpannableStringBuilder(31262): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
這將是有益的,如果你可以張貼logcat的運行系統。只是爲了理智檢查,你確實給你的應用程序互聯網權限? – roostertech
我確實給了它互聯網許可。我將馬上發佈logcat –