Android Jsoup post 请求 ASPX 页面总是出现 500 错误

Android Jsoup post request to ASPX page always get 500 error

我想开发一个停车收费的应用程序,结果我需要从网站上解析一些数据。我尝试了几个网站并成功了,但我总是在这个 webpage.
中得到 500 错误 以下是我的代码

Connection.Response resource = Jsoup.connect("http://tcparking.taichung.gov.tw/Parking/Parking/ParkingFee.aspx")
    .method(Connection.Method.GET)
    .execute();
Document document = Jsoup.connect("http://tcparking.taichung.gov.tw/Parking/Parking/ParkingFee.aspx")
    .data("__VIEWSTATE", resource.parse().getElementById("__VIEWSTATE").val())
    .data("__EVENTVALIDATION", resource.parse().getElementById("__EVENTVALIDATION").val())
    .data("ctl00$ContentPlaceHolder1$car_no", "ALZ-3586")
    .data("ctl00$ContentPlaceHolder1$CarType", "C")
    .data("__EVENTTARGET:", "")
    .data("__EVENTARGUMENT:", "")
    .data("__VIEWSTATEENCRYPTED:", "")
    .header("Content-Type", "application/x-www-form-urlencoded")
    .cookies(resource.cookies())
    .post();

然而,我总是

W/System.err: org.jsoup.HttpStatusException: HTTP error fetching URL. Status=500, URL=http://tcparking.taichung.gov.tw/Parking/Parking/ParkingFee.aspx
W/System.err:     at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:537)
W/System.err:     at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:493)
W/System.err:     at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:205)
W/System.err:     at com.lai.smith.parkingfee.asyncparse.AsyncTaizhong.doInBackground(AsyncTaizhong.java:54)
W/System.err:     at com.lai.smith.parkingfee.asyncparse.AsyncTaizhong.doInBackground(AsyncTaizhong.java:23)
W/System.err:     at android.os.AsyncTask.call(AsyncTask.java:288)
W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err:     at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:231)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/System.err:     at java.lang.Thread.run(Thread.java:841)

同时我可以成功访问后缀为chrome的网站-postman
--------------------------图1-------------------- ------

-------------------------图2---------------- ----------

我尝试像在 postman 中添加的那样在 jsoup 中添加所有内容,但仍然出现 500 错误,谁能帮我找出问题所在?

表格数据有误。三个数据参数末尾有无效的colon。 ASP.Net 服务器因此无法找到参数 __EVENTTARGET__EVENTTARGET__VIEWSTATEENCRYPTED.

替换下面三行

.data("__EVENTTARGET:", "")
.data("__EVENTARGUMENT:", "")
.data("__VIEWSTATEENCRYPTED:", "")

.data("__EVENTTARGET", "")
.data("__EVENTARGUMENT", "")
.data("__VIEWSTATEENCRYPTED", "")

我用这个调整测试了你的原始代码,Jsoup post 对 ASPX 页面的请求现在得到 200 OK 代码。