Web服务响应未从我的服务器返回 - java

我正在开发Android应用程序,并且出于测试目的,我在localhost上测试了它的运行状况,但是当我将该Web服务托管到服务器时,该URL没有响应返回。

=>我试过其他网址。

https://www.whizapi.com/api/v2/util/ui/in/indian-city-by-postal-code?AppKey=your-app-key&pin=110001

并正确获得响应,如下所示。

{"ResponseCode":2,"ResponseMessage":"Invalid App Key","ResponseDateTime":"1/6/2015 4:50:28 AM GMT","Data":[]}

但是从我的服务器url没有任何返回,并且应用程序显示继续加载数据。
这是我的doInBackgound()方法

 protected String doInBackground(String... strings) {
        try {



             try{
        // url where the data will be posted
        //String postReceiverUrl = "http://yoursmarthost.net/~html/androidtest/android_test.php";
        String postReceiverUrl="https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=API_KEY";
       // String postReceiverUrl="https://www.whizapi.com/api/v2/util/ui/in/indian-city-by-postal-code?AppKey=your-app-key&pin=110001";

        //String postReceiverUrl="http://'my  url'/android_test.php";
        Log.v(TAG, "postURL: " + postReceiverUrl);

        // HttpClient
        HttpClient httpClient = new DefaultHttpClient();

        // post header
        HttpPost httpPost = new HttpPost(postReceiverUrl);

        // add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("firstname", "Mike"));
        nameValuePairs.add(new BasicNameValuePair("lastname", "Dalisay"));
        nameValuePairs.add(new BasicNameValuePair("email", "[email protected]"));

        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // execute HTTP post request
        HttpResponse response = httpClient.execute(httpPost);
        HttpEntity resEntity = response.getEntity();

        if (resEntity!=null) {

            String responseStr = EntityUtils.toString(resEntity).trim();
            Log.v(TAG, "Response: " +  responseStr);


        }

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }



        } catch (NullPointerException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }

当我更改网址并将我的网络服务器的网址设为实时网址时

if (resEntity!=null) {

            String responseStr = EntityUtils.toString(resEntity).trim();
            Log.v(TAG, "Response: " +  responseStr);

        }

这里
调试指针输入EntityUtils.toString(resEntity).trim()方法,但不返回,并继续加载在android应用程序屏幕上显示。

参考方案

https://www.whizapi.com/api/v2/util/ui/in/indian-city-by-postal-code?AppKey=您的应用密钥和密码= 110001

在此url中,您必须实际编写您的应用程序密钥。

您可以通过登录whizapi.com来获取应用程序密钥,然后转到

https://www.whizapi.com/my-account

您可以通过单击网站右上角的Access WhizApi按钮登录whizapi.com。

Java-搜索字符串数组中的字符串 - java

在Java中,我们是否有任何方法可以发现特定字符串是字符串数组的一部分。我可以避免出现一个循环。例如String [] array = {"AA","BB","CC" }; string x = "BB" 我想要一个if (some condition to tell wheth…

Java Scanner读取文件的奇怪行为 - java

因此,在使用Scanner类从文件读取内容时,我遇到了一个有趣的问题。基本上,我试图从目录中读取解析应用程序生成的多个输出文件,以计算一些准确性指标。基本上,我的代码只是遍历目录中的每个文件,并使用扫描仪将其打开以处理内容。无论出于何种原因,扫描程序都不会读取其中的一些文件(所有UTF-8编码)。即使文件不是空的,scanner.hasNextLine()在…

Java Globbing模式以匹配目录和文件 - java

我正在使用递归函数遍历根目录下的文件。我只想提取*.txt文件,但不想排除目录。现在,我的代码如下所示:val stream = Files.newDirectoryStream(head, "*.txt") 但是这样做将不会匹配任何目录,并且返回的iterator()是False。我使用的是Mac,所以我不想包含的噪音文件是.DS_ST…

直接读取Zip文件中的文件-Java - java

我的情况是我有一个包含一些文件(txt,png,...)的zip文件,我想直接按它们的名称读取它,我已经测试了以下代码,但没有结果(NullPointerExcepion):InputStream in = Main.class.getResourceAsStream("/resouces/zipfile/test.txt"); Buff…

Java RegEx中的单词边界\ b - java

我在使用\b作为Java Regex中的单词定界符时遇到困难。对于text = "/* sql statement */ INSERT INTO someTable"; Pattern.compile("(?i)\binsert\b");找不到匹配项Pattern insPtrn = Pattern.compile(&…