douchui3933 2014-02-19 23:05
浏览 56
已采纳

从在线数据库中检索数据

I've got a simple database out on my GoDaddy account and I'm trying to retrieve data from it. I've set up a simple php file out on my account and can call it directly from a browser and it shows the retrieved data just fine. You can see it/run it here:

http://thunderbirdtechnology.com/SnapVest/php/SnapVestDatabaseRetrieveAvailableOptions.php

You'll get the following displayed:

[
    {
        "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"
    }
]

All well and good.

But then I'm trying to do that from my JAVA program running on my ANDROID phone. And it doesn't work. Here's the section of code:

        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 + "
");
            }

            inputStream.close();
            result = stringBuilder.toString();
        }
        catch(Exception e)
        {
            // Report "Error converting result"
            Toast.makeText(getBaseContext(),
                    "Error converting result", Toast.LENGTH_LONG).show();
        }

It does indeed retrieve some data. But here's the WEIRD PART! It's NOT retrieving my data from my database table. Instead, it's retrieving some ODD FILE from I-don't-know-where!

HERE'S A SAMPLE OF WHAT IT'S RETRIEVING:

<!--
   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">

What the heck is THAT? I have no clue who/what CyberTan is. Why am I not getting the data from my database? It seems to be connecting to it OK. It seems to be executing the php file OK, but what it actually returns is from some file I've never seen.

I'm totally confused. :)

  • 写回答

2条回答 默认 最新

  • dtu72460 2014-02-19 23:22
    关注

    Sure you are not getting firewall or packet inspection issues while on your mobile? CyberTan seems to make wifi / router products. I would check your home router for wireless and see if there is some protection thing blocking you. Similar to how some email servers will read your attachments and look for code.

    Also if you are seeing in your access logs that the webserver is being hit, then you are interested in the response coming back. Some good old tcpdump / wireshark will get you that info since its not over HTTPS

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 C#字典调用时报错,有关文件加载
  • ¥100 在连接内网VPN时,如何同时保持互联网连接
  • ¥15 MATLAB中使用parfor,矩阵Removal的有效索引在parfor循环中受限制
  • ¥20 Win 10 LTSC 1809版本如何无损提升到20H1版本
  • ¥50 win10 LTSC 虚拟键盘不弹出
  • ¥30 关于PHP中POST获取数据的问题
  • ¥30 微信小程序请求失败,网页能正常带锁访问
  • ¥15 Python实现hog特征图可视化
  • ¥30 德飞莱51单片机实现C4炸弹
  • ¥50 CrossLink-LIF-MD6000 型 FPGA 的 CMOS 转 MIPI D-PHY IP 核功能使用异常