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 网络科学导论,网络控制
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)