如何从改造中获得原始地址?

时间:2019-01-25 08:49:35

标签: android retrofit retrofit2

我收到改造请求对服务器上“ var TotalChkBx; $("input:checkbox").on("click", function() { var n = $("input:checkbox").index(this); $('#detail').append("Column 1" + $("table#DeviceTable tbody tr:eq(" + n + ") td:eq(1) ").text() + '<br/>'); $('#detail').append("Column 2" + $("table#DeviceTable tbody tr:eq(" + n + ") td:eq(2) ").text() + '<br/>'); $('#detail').append("Column 3" + $("table#DeviceTable tbody tr:eq(" + n + ") td:eq(3) ").text() + '<br/>'); $('#detail').append("Column 4" + $("table#DeviceTable tbody tr:eq(" + n + ") td:eq(4) ").text() + '<br/>'); }); function CheckAll(CheckBox) { $('#detail').html(""); var TargetBaseControl = document.getElementById("DeviceTable"); // objRef.parentNode.parentNode.parentNode; var TargetChildControl = "check"; //var Check_TEXT = "CHECK_CheckBox" var Inputs = TargetBaseControl.getElementsByTagName("input"); // var Spans = TargetBaseControl.getElementsByTagName("span"); for (var n = 0; n < Inputs.length; ++n) { if ((Inputs[n].type === 'checkbox')) // { Inputs[n].Checked = CheckBox.checked; $("#" + Inputs[n].id).attr("Checked", CheckBox.checked); $('#detail').append("Column 1" + $("table#DeviceTable tbody tr:eq(" + n + ") td:eq(1) ").text() + '<br/>'); $('#detail').append("Column 2" + $("table#DeviceTable tbody tr:eq(" + n + ") td:eq(2) ").text() + '<br/>'); $('#detail').append("Column 3" + $("table#DeviceTable tbody tr:eq(" + n + ") td:eq(3) ").text() + '<br/>'); $('#detail').append("Column 4" + $("table#DeviceTable tbody tr:eq(" + n + ") td:eq(4) ").text() + '<br/>'); } // else { $('#detail').html("");} } Counter = CheckBox.checked ? TotalChkBx : 0; }”链接的响应,其中id-查询参数。当我从改造中获得响应时,我已经链接了已经粘贴的参数“ <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <table id="DeviceTable" class="table table-bordered"> <thead> <tr class="info"> <th style="width: 10px;"> <input type="checkbox" id="check1" name="checkBox" id="check_selectall-custom" onclick="CheckAll(this)" />SA</th> <th>Device</th> <th> Type</th> <th> Model</th> <th> Status</th> </tr> </thead> <tbody class="parameter_table"> <tr id="tr_device_id1"> <td> <input type="checkbox" id="check2" name="checkBox"> </td> <td id="macadd" style="word-break:break-all;"> Mac1 </td> <td style="word-break:break-all;"> Dev 1 </td> <td style="word-break:break-all;"> Model 1 </td> <td class="Selected_Device" id="Selected_Device"> <b id="Selected_Device" style="float: right;"></b> </td> </tr> <tr id="tr_device_id2"> <td> <input type="checkbox" id="check3" name="checkBox"> </td> <td id="macadd" style="word-break:break-all;"> Mac 2 </td> <td style="word-break:break-all;"> Parm 2 </td> <td style="word-break:break-all;"> Model 2 </td> <td class="Selected_Device" id="Selected_Device"> <b id="Selected_Device" style="float: right;"></b> </td> </tr> </tbody> </table> <div id="detail"></div>”。如何在翻新(/address/{id}/data)中获得无查询的原始链接?

1 个答案:

答案 0 :(得分:0)

您可以做什么

您可能还有其他选择,但是您可以从此开始

选项1

您可以使用

直接从改造返回的响应中访问网址。
response.raw().request().url()

这将返回请求的http网址,例如。打印出来

okhttp/example-request D: //http://example.com/address/001/data

选项2

另一种方法是在okhttp-logging-inceptor的帮助下添加网络请求拦截器。

val logging = HttpLoggingInterceptor()
logging.level = Level.BASIC
val client = OkHttpClient.Builder()
    .addInterceptor(logging)
    .build()

选项2比选项1更好,因为它将拦截应用程序中的所有网络请求,而无需在每个请求回调上都做很多工作。另外,您可以选择自定义其日志记录级别,并仅在指定条件下添加它。

例如。默认登录为调试模式

val logging = HttpLoggingInterceptor(HttpLoggingInterceptor.Logger.DEFAULT)
val client = OkHttpClient.Builder()
if (BuildConfig.DEBUG) {
    logging.level = HttpLoggingInterceptor.Level.BODY // setting the level
    client.addInterceptor(okHttpLoggingInterceptor) // adding interceptor
}

参考