为R httr库模拟Fiddler中的500错误
我有一个闪亮的web应用程序,我想测试我的代码是否有来自API的500个错误。我的应用程序正在使用httr库。我在fiddler中设置了这个:为R httr库模拟Fiddler中的500错误,r,http,proxy,fiddler,httr,R,Http,Proxy,Fiddler,Httr,我有一个闪亮的web应用程序,我想测试我的代码是否有来自API的500个错误。我的应用程序正在使用httr库。我在fiddler中设置了这个: static function OnBeforeResponse(oSession: Session) { if (m_Hide304s && oSession.responseCode == 304) { oSession["ui-hide"] = "true"; } if (oSession.u
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")
}
path找到了,我需要使用:
oSession.oRequest.FailSession(500, "Blocked", "Fiddler blocked this request");