【问题标题】:SMF.Net.WebClient - empty response from a web-siteSMF.Net.WebClient - 来自网站的空响应
【发布时间】:2015-06-02 12:20:50
【问题描述】:

我已经成功使用 SMF.Net.WebClient 访问了一个网站。现在它在请求某个链接时有奇怪的行为:

  var wc = new SMF.Net.WebClient({
    URL : "http://www.invitro.ru/analizes/for-doctors/156/6671/?region_code=&section_id=156&element_id=6671",
    httpMethod : "GET",
    requestHeaders : ["Content-Type: text/html"],
    // When results are ready
    onSyndicationSuccess : function (e) {
        Pages.Webview.WV_Main.URL = this.responseText;
        Pages.Webview.show();            
    }, 
    timeoutInterval : 15        
  }); 
wc.run(true);

在这种情况下,onSyndicationSuccess responseText 始终为空,尽管 this.status = 200。

我什至用 Excel VBA 中的相同参数和 URL 尝试了 XmlHttpRequest。效果很好!

这里可能有什么问题?

【问题讨论】:

  • 使用 WebClient 获取 html 响应似乎有问题。为什么您使用 webCLient 来显示带有 WebView 的 HTML。 WebClient 一般用于获取 JSON Restful 服务。您可以直接将 URL 提供给 WebView。
  • 处于测试模式。我需要在代码中解析 html-response 以从页面中获取一些数据。是否有更合适的方法来实现我的目标?
  • 我建议你使用runJS方法来达到那种目的smartface.io/developer/guides/controls/webview/…
  • 谢谢!很好的建议!

标签: xmlhttprequest smartface.io


【解决方案1】:

解决问题的一种可能方法 - 以特殊方式使用 SMF.UI.WebView 对象:

Pages.Webview.WV_Main.URL = ....
...
function Webview_WV_Main_OnLoad(e){
    var js = "document.body.innerHTML"

    Pages.Webview.WV_Main.runJS({javascript:js, callback:function(e){ 
        // e.result here is a string containing html-response
        }});  
}

【讨论】:

    猜你喜欢
    • 2012-10-26
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 2014-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-24
    相关资源
    最近更新 更多