繁体   English   中英

我正在获取HTML代码而不是JSON作为响应

[英]I am getting HTML code instead of JSON in response

当我在android中使用HttpUrlConnection触发我的URL( URL here )时,响应中给出的是HTML代码而不是JSON。请帮我解决这个问题。

<html>
<body>
    <script type="text/javascript" src="/aes.js" ></script>
    <script>function toNumbers(d){var e=[];d.replace(/(..)/g,function(d){e.push(parseInt(d,16))});return e}function toHex(){for(var d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f
        <d.length;f++)e+=(16>d[f]?"0":"")+d[f].toString(16);return e.toLowerCase()}var a=toNumbers("f655ba9d09a112d4968c63579db590b4"),b=toNumbers("98344c2eee86c3994890592585b49f80"),c=toNumbers("f1f002aa0df1b14d95e07de0f61fa7da");document.cookie="__test="+toHex(slowAES.decrypt(c,2,a,b))+"; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/"; location.href="http://health.ultimatefreehost.in/E-H/production/mobile/mFeedList?i=1";
        </script>
        <noscript>This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support</noscript>
    </body>
</html>

以下是我的Android代码。

URL url = new URL(reqUrl);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        // read the response
        InputStream in = new BufferedInputStream(conn.getInputStream());
        response = convertStreamToString(in);

注意:但是在浏览器中,它会给出正确的JSON响应。

在寻找Internet解决方案时,我发现的一个简单技巧就是在打开Android应用程序之前先进入手机浏览器中的URL。 即使您先关闭浏览器,它也可以正常工作。 我不知道为什么这样。 可能是因为电话浏览器已访问该文件以查看服务器以某种方式知道将信息传递给使用同一设备的应用程序的JSON对象/数组? 将会进行进一步的测试,看看它会去哪里,但是现在我的应用程序正在运行,并且这个技巧将是我下次遇到这些错误时尝试的第一件事。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM