带帖子下载以隐藏用户名和密码?

时间:2019-04-15 14:03:04

标签: javascript

我有下面的代码。我想使用Post()而不是Get(),因为我不想在字符串中显示用户名和密码。首先,我获得身份验证并使用post()下载cookie。这很好。但是,然后我用get()下载了一个xml文件,并且用户名和密码在下载字符串中可见。如何使用post()下载Latest.xml?如果我更改为post wre,但我却没有任何文件(latest.xml)(如果我更改为Post(),则不起作用。)

URL是https而不是http。

var apiUrl = s.getPropertyValue('apiUrl');
var apiUser = s.getPropertyValue('apiUser');
var apiPass = s.getPropertyValue('apiPass');
var anyOrders = "";

var theHTTP = new HTTP();
theHTTP.resetParameters();
theHTTP.url = apiUrl + "/wsauth?";
theHTTP.addParameter("username", apiUser);
theHTTP.addParameter("password", apiPass);
theHTTP.authScheme = HTTP.BasicAuth;
theHTTP.post(); //Works fine

while( !theHTTP.waitForFinished( 1 ) ) { }
job.log(-1, "Server response: " + theHTTP.getServerResponse().toString("UTF-8"));


if( theHTTP.finishedStatus != HTTP.Ok )
{
    job.fail("The request failed: %1", theHTTP.lastError);
    return;
}

var theCookie = theHTTP.getHeaderValue( HTTP.SetCookie ).toString( "UTF-8" );
if( theCookie.isEmpty() )
{
    job.fail("Invalid cookie response: %1", theHTTP.lastError);
    return;
}

s.log(-1, "Cookie: " + theCookie);

//Perform query to get xml file 
theHTTP.addHeader( HTTP.Cookie, theCookie );
theHTTP.url = apiUrl + "/order/latest";

theHTTP.localFilePath = job.createPathWithName("latest.xml", false); 

job.log(1,theHTTP.localFilePath, false);
theHTTP.get(); //Does not work if I change to Post()

job.log( 4, "Download started", 100 );
while( !theHTTP.waitForFinished( 3 ) ) {
    job.log( 5, "Downloading...", theHTTP.progress() );
}
job.log( 6, "Download finished" );

//open file to read if there are any orders
var f = new File(theHTTP.localFilePath);
f.open(File.ReadOnly);
anyOrders = f.read();
f.close();

if( theHTTP.finishedStatus == HTTP.Ok && File.exists(theHTTP.localFilePath)) {
    if(anyOrders == "No non-processed order found!") {
        job.sendToNull( job.getPath() );
        job.log( 1, "No non-processed order found! File deleted!");
    } else {
        job.log( 1, "Download completed successfully");
        job.sendToSingle(theHTTP.localFilePath);
    }
}
else {
    job.fail("Download failed with the status code %1", theHTTP.statusCode);
    job.sendToNull( job.getPath() );
    return;
}

0 个答案:

没有答案