Если я запускаю следующий код, когда он отображает правильный результат.
library(data.table)
library(jsonlite)
library(httr)
library(properties)
library(futile.logger)
library(crayon)
library(XML)
library(methods)
library(compare)
library(tictoc)
#-----------------------------------------------------
args = commandArgs(trailingOnly=TRUE)
host.name = "lgloz050.lss.emc.com"
port = "58443"
default.path = "/APG/lookup/"
#Set the working directory
# NOTE : this location has to be passed externally as a param
wd.name = "C:\\Users\\sharmb5\\Documents\\R script_RR"
setwd(wd.name)
#Set Default Configurations.
set_config(config(ssl_verifypeer = 0L))
#-----------------------------------------------------
# Read the configurtion file
#-----------------------------------------------------
config <- fread("Configuration.csv")
config$bc <- config$testReport
# let us filter the reports which are not enabled for fetch / compare .i,e, reportMatch = NO
config <- config[reportsMatch %in% c("yes","YES","TRUE")]
#breadcrumbs & spaces handling
config$testReport <- gsub(">>","/",config$testReport)
config$testReport <- gsub(" ","%20",config$testReport)
config$URL <- paste("https://",host.name,":",port,default.path,config$testReport,"/report.csv", sep = "")
# $place_holder filler
properties = read.csv2("resources/configuration.properties",sep = "=", blank.lines.skip = TRUE,header = FALSE,stringsAsFactors = FALSE )
colnames(properties) <- c("key","value")
config$URL <- gsub( "\\$" , "PH_" , config$URL )
for(i in 1:nrow(properties)){
if(startsWith(properties[i,1],"$")){
print(properties[i,1])
for (j in 1: nrow(config)) {
config[j]$URL = gsub(paste("PH_",substring(trimws(properties[i,1]),2),sep = "")
,trimws(properties[i,2]),config[j]$URL,ignore.case = TRUE)
}
}
}
#result <- config
result <- config[,list(bc,TestCaseID,URL),]
#------------------------------------------------
# Fetch Report Data
#------------------------------------------------
# Auth Function
auth <- function(URL,user.name="admin", password="changeme"){
# Only for first time login
res <- GET(URL,add_headers("accept"="text/json"))
res <- POST('https://lgloz050.lss.emc.com:58443/APG/j_security_check'
,set_cookies=res$cookies
,body = "j_username=******&j_password=******"
,add_headers("Content-Type" ="application/x-www-form-urlencoded" ))
return(res)
}
# Fetch Function
fetch <- function(URL,save.location,cookies){
fetch.success = TRUE
res <- GET(URL
,add_headers("Authorization"="Basic *************")
,set_cookies=cookies)
tryCatch({repot_data <- fread(content(res,"text"),header = TRUE);
# write.csv(data.frame(repot_data),save.location,row.names = FALSE);
fwrite(data.frame(repot_data),save.location,row.names = FALSE);
flog.info(green("'\u2713' - Fetch Completed successfully ..."))
flog.info(paste("URL : ",URL))}
#,warning=function(w){flog.warn(paste("warnings while fetching data "))}
,error = function(e){fetch.success= FALSE; flog.error(paste("\u2715 - Not able to fetch data,file not created "))})
return(fetch.success)
}
config$save.location = sub("TruthData","testData",config$truthReport,ignore.case = T)
response = auth(config[1]$URL)
response
во время второго выполнения кода, он выдаст следующий сценарий:
Response [https://lgloz050.lss.emc.com:58443/APG/j_security_check]
Date: 2019-01-21 10:20
Status: 404
Content-Type: text/html;charset=utf-8
Size: 1.12 kB
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=10,chrome=1" />
<title>Oops!</title>
<link id="app-context" rel="shortcut icon" href="/APG/img/favicon.ico" />
<link rel="stylesheet" href="/APG/css/apg.misc.min.css" />
<script>var require = { baseUrl: '/APG/js', config: { i18n: { locale: 'en-us' } } };</script>
<script src="/APG/js/apg.misc.min.js"></script>
Опять же, если я меняю устройство, то с этим новым устройством оно будет работать хорошо в первый раз, и если снова захочется запустить, оно будет отображаться, как указано выше.
Как мне разрешить этот повторный вход в систему?
Заранее спасибо.