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 三菱伺服电机按启动按钮有使能但不动作
  • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号