我在GoDaddy帳戶中有一個簡單的數據庫,我試圖從中檢索數據。我已經在我的帳戶中設置了一個簡單的php文件,並可以直接從瀏覽器調用它,並顯示檢索到的數據就好。你可以看到它/這裏運行:從在線數據庫檢索數據
http://thunderbirdtechnology.com/SnapVest/php/SnapVestDatabaseRetrieveAvailableOptions.php
你會得到如下顯示:
[
{
"ID": "1",
"CompanyName": "Yahoo Inc.",
"DateInvestStart": "2014-02-19 14:35:56",
"DateInvestEnd": "2014-02-28 11:35:44",
"DatePurchase": "2014-03-11 11:35:51"
}
]
一切都很好。
但後來我試圖從我的ANDROID手機上運行的JAVA程序那樣做。它不起作用。以下是代碼段:
InputStream inputStream = null;
String result = "";
try
{
HttpClient httpclient = new DefaultHttpClient();
// Here is where we specify where our php file (see sample above) is that will do the actual
// gathering up of the data.
HttpPost httppost = new HttpPost("http://www.ThunderbirdTechnology.com/SnapVes/php/SnapVestDatabaseRetrieveAvailableOptions.php");
HttpResponse httpresponse = httpclient.execute(httppost);
HttpEntity httpentity = httpresponse.getEntity();
inputStream = httpentity.getContent();
}
catch(Exception e)
{
// Report "Error in http connect to database"
Toast.makeText(getBaseContext(),
"Error in http connect to database", Toast.LENGTH_LONG).show();
}
try
{
// Convert response to string
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"),8);
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null)
{
stringBuilder.append(line + "\n");
}
inputStream.close();
result = stringBuilder.toString();
}
catch(Exception e)
{
// Report "Error converting result"
Toast.makeText(getBaseContext(),
"Error converting result", Toast.LENGTH_LONG).show();
}
它確實檢索了一些數據。但這是WEIRD PART!它不是從我的數據庫表中檢索我的數據。相反,它從我不知道的地方檢索一些ODD文件!
這裏是什麼它是檢索示例:
<!--
Copyright 2003, CyberTAN Inc. All Rights Reserved
This is SOURCE CODE of CyberTAN Inc.
the contents of this file may not be disclosed to third parties,
copied or duplicated in any form without the prior written
permission of CyberTAN Inc.
This software should be used as a reference only, and it not
intended for production use!
THIS SOFTWARE IS OFFERED "AS IS", AND CYBERTAN GRANTS NO WARRANTIES OF ANY
KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. CYBERTAN
SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE
-->
<HTML><HEAD><TITLE></TITLE>
<meta http-equiv="expires" content="0">
<meta http-equiv="cache-control" content="no-cache">
到底是什麼呢?我不知道CyberTan是誰/什麼。爲什麼我沒有從我的數據庫中獲取數據?它似乎連接到它可以。它似乎在執行php文件,但它實際返回的是來自我從未見過的文件。
我完全困惑。 :)
您是否嘗試過使用您的Java代碼也是JSON的不同端點? – Newbi3