here is the code
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://page/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "frashnum=&action=login&Frm_Logintoken=4&Username=admin&Password=admin");
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
?>
i got it using Curl-to-PHP
by converting this command to php
curl "http://page/" --data "frashnum=&action=login&Frm_Logintoken=24&Username=admin&Password=admin"
and i need to get the value of the login token using this XMLHttpRequest request and js code first
<!DOCTYPE html>
<html>
<body>
<script>
httpRequest = new XMLHttpRequest()
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState == XMLHttpRequest.DONE) {
let str =(httpRequest.responseText);
alert(str)
let pattern =/\bgetObj\("Frm_Logintoken"\)\.value = "([^"]+)";/;
console.log(str.match(pattern)[1]);
}
}
httpRequest.open('GET', 'http://page/', true);
httpRequest.send(null);
</script>
</body>
</html>
so i need to replace the Frm_Logintoken value with the console.log(str.match(pattern)1); result
what i have tried and failed
<!DOCTYPE html>
<html>
<body>
<script>
var xhr = new XMLHttpRequest();
xhr.open('post','http://page/', true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onload = function () {
// do something to response
console.log(this.responseText);
};
xhr.send('document.getElementById("Frm_Username").value = "test"');
xhr.send('document.getElementById("Frm_Password").value = "test"');
xhr.send('function dosubmit()');
</script>
</body>
</html>
it give me this error
Uncaught DOMException: Failed to execute 'send' on 'XMLHttpRequest': The object's state must be OPENED.
And i don't know how to define the match console.log(str.match(pattern)[1]);
results out of the function in the first js code
and there is something that i am Not sure about do i need the login token just like the php code or i can just insert the data then use the function function dosubmit()
that's in the code of the page we are sending the data to !