Forum Discussion
- AlexKarasChampion Level 3Hi Igor,
Have a look at samples at http://www.automatedqa.com/support/viewarticle.aspx?aid=8999 and http://www.automatedqa.com/support/viewarticle.aspx?aid=9000, hope they will help... - joker6413Occasional ContributorThank's a lot.
- joker6413Occasional ContributorFinal version of script:
function HttpGet(url, userAgent)
{
var httpObj = Sys.OleObject("MSXML2.XMLHTTP");
httpObj.open("GET", url, true);
httpObj.setRequestHeader("User-Agent", userAgent); // set user agent
httpObj.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"); /// do not cache the response
httpObj.send();
while((httpObj.readyState != 4) && (httpObj.readyState != 'complete'))
{
Delay(300);
}
switch(httpObj.status)
{
case 200:
case 302:
if (httpObj.responseText.lenght == 0) //!= expectedObjectData)
{
Log.Message("The " + link + " link is valid", httpObj.responseText);
return false;
}
return httpObj.responseText;
break;
default:
Log.Message("The " + link + " link was not found, the returned status: " +
httpObj.status, httpObj.responseText);
return false;
}
} - MatroskinOccasional Contributor
hello
can i scrips same function by using delphiscript?
i tried it, but "httpObj.open("GET", url, true);" calls "unknown error"
- radovStaffHi Vladimir,
The following code is a DelphiScript version of the function. Note that I've modified a bit the original program logic of the code posted earlier by Igor. However, you can change the code of the function if you need and implement your own program logic in it.
function HttpGet(url, userAgent): boolean;
var
httpObj: OleVariant;
begin
httpObj := Sys.OleObject['MSXML2.XMLHTTP'];
httpObj.open('GET', url, true);
httpObj.setRequestHeader('User-Agent', userAgent); // set user agent
httpObj.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT'); /// do not cache the response
httpObj.send();
while(httpObj.readyState <> 4) do
Delay(300);
case httpObj.status of
200, 302 :
if Length(httpObj.responseText) <> 0 then
begin
Log.Message('The ' + url + ' link is valid', httpObj.responseText);
Result := false;
end
else
Result := true;
else
begin
Log.Message('The ' + url + ' link was not found, the returned status: ' +
aqConvert.VarToStr(httpObj.status), httpObj.responseText);
Result := false;
end
end
end;
Does this help? - MatroskinOccasional Contributor
thanks for your answer.
when i posted message about error, tried to execute this script:
procedure RequestTest;
var i:olevariant;
begin
try
i:= Sys.OleObject('MSXML2.XMLHTTP');
i.open('GET', '192.168.0.106/Some.Service/action.aspx?src=someSourse&dest=someDest&message=someMessage', True);delay(5000);
Log.Event(i.readyState);
except
Log.Error('Exception', ExceptionMessage)
end;
end;at string, which contains " i.open('GET', '192.16.." i got an error. you proposed me almost same code, excluding minor parameters. right now
this function
is written , but with making request by telnet. i hope is temprorary ) - tristaanogreEsteemed ContributorI'm guessing there's something wrong with your URL. Try actually using the "http://" designator at the beginning of the URL and see if that corrects it.
- MatroskinOccasional Contributor
thanks alot.
sorry for this dummy mistake )
Related Content
- 10 years ago
- 5 years ago
- 4 years ago
Recent Discussions
- 6 days ago
- 6 days ago
- 9 days ago