我看过其他类似的帖子,但没有什么明显的东西是跳出来的。如果我错过了,我肯定有人会给我指明正确的方向!
问题是,我的应用程序中的这段代码曾经工作过,但现在不再工作了。所以我假设网站上发生了一些变化。在同一应用程序中,我对其他三个网站使用了完全相同的代码,它们运行得很好。LOGCAT显示以下错误:
org.jsoup.HttpStatusException: HTTP错误获取URL。Status=403,URL=Aerodrome.php
我制作了这个简单的网页,我可以从本地驱动器启动它,并且它可以工作(如果您自己尝试它,您需要调整日期和时间以适应当前的UTC时间):
<form method="post" action="http://notamweb.aviation-civile.gouv.fr/Script/IHM/Bul_Aerodrome.php">
Enter aerodrome ID(s)
<input type="text" name="AERO_Tab_Aero[0]">
<input type="hidden" name="AERO_Date_DATE" value="2016/01/25">
<input type="hidden" name="AERO_Date_HEURE" value="07:12">
<input type="hidden" name="bResultat" value="true">
<input type="hidden" name="ModeAffichage" value="COMPLET">
<input type="hidden" name="AERO_Duree" value="96">
<input type="hidden" name="AERO_CM_REGLE" value="1">
<input type="hidden" name="AERO_CM_GPS" value="2">
<input type="hidden" name="AERO_CM_INFO_COMP" value="1">
<p>
<input type="Submit" value="Get the bulletins">
</p>
</form>此代码返回错误:
doc = Jsoup.connect("http://notamweb.aviation-civile.gouv.fr/Script/IHM/Bul_Aerodrome.php")
.data("bResultat", "true").data("ModeAffichage", "COMPLET")
.data("AERO_Date_DATE", date).data("AERO_Date_HEURE", time).data("AERO_Duree", "96").data("AERO_CM_REGLE", "1").data("AERO_CM_GPS", "2")
.data("AERO_CM_INFO_COMP", "1").data("AERO_Tab_Aero[0]", params[0].substring(0, params[0].length() - 1))
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36")
.timeout(6000).post();有什么想法?
编辑1:当我使用我的迷你网页时看到的标题是:
请求头接受:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8 接受-编码:gzip,放气 接受-语言:en-US,en;q=0.8,en-AU;q=0.6 缓存-控制:最大年龄=0 连接:保持-活着 内容长度:180 Content-Type:application/x-www-form-urlencoded 主办单位:notamweb.aviation.航空-民间航空公司 原产地:空 升级-不安全-请求:1 用户代理:Mozilla/5.0(WindowsNT6.1;WOW64) AppleWebKit/537.36 (KHTML,类似壁虎) Chrome/47.0.2526.111 Safari/537.36 表格数据 AERO_Tab_Aero:KLAX 航空日期:2016/01/25 AERO_Date_HEURE:11:21 B结果:真 ModeAffichage: AERO_Duree:96 AERO_CM_REGLE:1 AERO_CM_GPS:2 AERO_CM_INFO_COMP:1
发布于 2016-01-25 13:27:53
JonasCz的帮助创意
解决这个问题的一种方法是在桌面浏览器中加载页面,并查看developer tools的网络选项卡,看看它到底发送了什么,特别是cookie和headers。我的猜测是,您需要发送其他/额外的cookie,或可能是一个参考标题,因为网站可能正在检查这一点,然后发送相同或类似的标题/cookie与您的请求。
发布于 2016-01-26 13:33:58
问题解决了。问题是仿真器时钟错误,导致网页拒绝请求。
https://stackoverflow.com/questions/34987357
复制相似问题