【问题标题】:Simulate 500 error in Fiddler for R httr library在 Fiddler for R httr 库中模拟 500 错误
【发布时间】:2018-02-22 13:40:06
【问题描述】:

我有闪亮的网络应用程序,我想测试我的代码是否存在来自 API 的 500 个错误。我的应用程序正在使用 httr 库。我已经在提琴手中设置了这个:

static function OnBeforeResponse(oSession: Session) {
    if (m_Hide304s && oSession.responseCode == 304) {
        oSession["ui-hide"] = "true";
    }
    if (oSession.url.Contains("study.xml")) {
        oSession.oResponse.headers.HTTPResponseCode = 500;
        oSession.oResponse.headers.Add("Foo", "Bar");
    }
}

在 R 代码中我有这个:

  path <- paste0(
    url,
    "/study.xml/", .session$sid, "/analysis_data"
  )
  res <- GET(path, use_proxy("127.0.0.1", 8888))
  print(paste(path, res$status_code))
  print(json(headers(res)))
  if (res$status_code == 500) {
    # handler error
    stop("error 500")
  }

即使我在 Fiddler 中有 500 个响应,在 R 中我有 200 个,标题设置正确,当页面返回 404 时,我得到 404 响应。

还有其他方法可以在 fiddler 中模拟 500 错误代码吗?我发现 Fiddler 脚本最简单,因为我不需要摆弄 Fiddler 界面。

【问题讨论】:

    标签: r http proxy fiddler httr


    【解决方案1】:

    找到了,我需要使用:

    oSession.oRequest.FailSession(500, "Blocked", "Fiddler blocked this request");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-28
      • 1970-01-01
      相关资源
      最近更新 更多