1

我试图让我的用户能够报告我的 android 应用程序自动捕获到我的服务器的小错误。它没什么大不了的,只是一个小文本框和发送按钮。

它应该将 3 个字符串(错误、可选的用户描述和时间)发送到我网站上专门用于捕获这些错误的文件。问题是,我完全不知道该怎么做。我只知道如何让我的应用程序从我的网站读取信息,但不知道相反。

我必须在我的网站上有一个特殊的脚本吗?JSON字符串是必需的吗?我需要将字符串保存在那里。(不是暂时的)我有点新手所以任何帮助表示赞赏。谢谢!

4

2 回答 2

0

您只需通过 http 将值发布到服务器上的 php 脚本,该脚本会将这些值保存在您的文件或数据库中。

于 2012-11-21T06:16:58.603 回答
0

-必须script在您的服务器上运行,例如:php script.

-它实际上是在服务器上发布的Web 服务,以便客户端可以访问它。

-然后你需要对HTTP Post服务器做一个,它最好NameValuePair与它一起使用来发送数据。

这是我做 HTTP POST 的代码:

public String postData(String url, String xmlQuery) {

        final String urlStr = url;
        final String xmlStr = xmlQuery;
        final StringBuilder sb = new StringBuilder();

        Thread t1 = new Thread(new Runnable() {

            public void run() {

                HttpClient httpclient = MySSLSocketFactory.getNewHttpClient();

                HttpPost httppost = new HttpPost(urlStr);

                try {

                    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
                            1);
                    nameValuePairs.add(new BasicNameValuePair("xml", xmlStr));

                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                    HttpResponse response = httpclient.execute(httppost);

                    Log.d("Vivek", response.toString());

                    HttpEntity entity = response.getEntity();
                    InputStream i = entity.getContent();

                    Log.d("Vivek", i.toString());
                    InputStreamReader isr = new InputStreamReader(i);

                    BufferedReader br = new BufferedReader(isr);

                    String s = null;

                    while ((s = br.readLine()) != null) {

                        Log.d("YumZing", s);
                        sb.append(s);
                    }

                    Log.d("Check Now", sb + "");

                } catch (ClientProtocolException e) {

                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } /*
                 * catch (ParserConfigurationException e) { // TODO
                 * Auto-generated catch block e.printStackTrace(); } catch
                 * (SAXException e) { // TODO Auto-generated catch block
                 * e.printStackTrace(); }
                 */
            }

        });

        t1.start();
        try {
            t1.join();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        System.out.println("Getting from Post Data Method " + sb.toString());

        return sb.toString();
    }

////////////////////////////////////////////////////////////////////////// ///////////////

服务器端php代码:

<?php

require_once(ROOT.'/lab/lib/xyz_api_int.php');

try {

    //setup the sdk
    $api = YumzingApiInt::_get(
        Config::get('api_int','url'),
        Config::get('api_int','key'),
        Config::get('api_int','secret')
    );

    //connect to the api
    $api->connect();

    //check our token
    echo $api->getToken();

} catch(Exception $e){
    sysError($e->getMessage());
}
于 2012-11-21T06:46:26.190 回答