android – Http Get Request返回html?

android – Http Get Request返回html?,第1张

概述我正在使用http get Request在 android中加载数据.不知道它返回html而不是 JSON结果.在浏览器中加载时,相同的URL获取json,但响应来自html. 我的Http Get call格式就像这样…… url = new URL(urlString); //httpURLConnection = (HttpsURLConnection) url.open 我正在使用http get Request在 android中加载数据.不知道它返回HTML而不是 JSON结果.在浏览器中加载时,相同的URL获取Json,但响应来自HTML.

我的http Get call格式就像这样……

url = new URL(urlString);        //httpURLConnection = (httpsURLConnection) url.openConnection();        httpURLConnection = (httpURLConnection) url.openConnection();        httpURLConnection.setRequestMethod("GET");        httpURLConnection.setRequestProperty("Connection","keep-alive");        httpURLConnection.setRequestProperty("Accept","application/Json"); // or application/Jsonrequest        httpURLConnection.setRequestProperty("Content-Type","application/Json");        /*        httpURLConnection.setRequestProperty("Content-Type","application/Json");*/        httpURLConnection.setRequestProperty("UsecookieContainer","True");        httpURLConnection.setRequestProperty("cookie",cokIEValue);        httpURLConnection.connect();
解决方法 一旦检查了服务器端代码..
即将到来意味着改变这样的代码……

url = new URL(urlString);        httpURLConnection = (httpsURLConnection) url.openConnection();        //httpURLConnection = (httpURLConnection) url.openConnection();    //  httpsURLConnection.setDefaultHostnameVerifIEr(new NullHostnameVerifIEr());        httpURLConnection.setRequestMethod("GET");        httpURLConnection.setRequestProperty("Connection","keep-alive");        httpURLConnection.setRequestProperty("Content-Type","application/Json");        httpURLConnection.setRequestProperty("UsecookieContainer","True");        httpURLConnection.setChunkedStreamingMode(0);        httpURLConnection.connect();        if (httpURLConnection != null) {            respCode = httpURLConnection.getResponseCode();            messageStatus.setResponseCode(respCode);        }        if (respCode == 200) {            inputStream responseStream = httpURLConnection.getinputStream();            messageStatus.setResponseStream(responseStream);        }
总结

以上是内存溢出为你收集整理的android – Http Get Request返回html?全部内容,希望文章能够帮你解决android – Http Get Request返回html?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1127730.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存