Page 1 of 1

Help with get request in Json format 2

Posted: Fri Dec 15, 2017 3:09 pm
by sjuaq
Hi,

Here is another json question. The code is the same but for a diferent service. The idea is to fetch the IPs and show to the user by getting the string "ip_str". Also if this is done right is it possible to save every "ip_str" as a individual string that can be called later?
IP: <a id='show'></a>

<script>
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var myObj = JSON.parse(this.responseText);
document.getElementById("show").innerHTML = myObj.matches.ip_str;
}
};
xmlhttp.open("GET", "https://api.shodan.io/shodan/host/searc ... uery=xampp", true);
xmlhttp.send();
</script>
Thanks
I'm a noob i know. If possible include a few references/examples to how Json works.

Re: Help with get request in Json format 2

Posted: Fri Dec 15, 2017 3:25 pm
by requinix
myObj.matches is an array, not an object. Use a loop.

Re: Help with get request in Json format 2

Posted: Sat Dec 16, 2017 5:38 am
by sjuaq
Fixed thanks...

Also another question not related to json but with XMLHttp. I want to send basic http auth header using XMLHttp and make an action afterwards.

I will have to use a code similar to the below, right?
<script>
var xmlhttp = new XMLHttpRequest();
xmlhttp.setRequestHeader("Authorization", "Basic" + btoa("username:password"));
xmlhttp.open("GET", "http://127.0.0.1", true);
xmlhttp.send();

// And after authentication
xmlhttp2.open("GET", "http://127.0.0.1/test.php?add=entry", true);
xmlhttp2.send();
</script>
(I know that the code is not correct, how van i make it run?)

Re: Help with get request in Json format 2

Posted: Sat Dec 16, 2017 6:54 am
by requinix
setRequestHeader() goes after open() and before send(), but otherwise yes.

Re: Help with get request in Json format 2

Posted: Sat Dec 16, 2017 12:54 pm
by sjuaq
<input type="submit" name="submit" onclick=open();>
<script>
function = open() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "http://127.0.0.1", true);
xmlhttp.setRequestHeader("Authorization", "Basic" + btoa("username:password"));
xmlhttp.send();

// And after authentication
xmlhttp2.open("GET", "http://127.0.0.1/test.php?add=entry", true);
xmlhttp2.send();
}
</script>
I have made the adjustments but it doesn't fetch the page. I have tried with two different http servers and check the logs and it isn't nothing there. Do you know what is wrong with?

Thanks

Re: Help with get request in Json format 2

Posted: Sat Dec 16, 2017 5:42 pm
by requinix
1. Your Javascript syntax for a function is wrong.
2. There needs to be a space between the "Basic" and the encoded username and password
3. xmlhttp2 is undefined.
4. You don't seem to be passing or receiving any data.

Re: Help with get request in Json format 2

Posted: Sat Oct 06, 2018 10:36 am
by sjuaq
@requinix - I found the solution...

Thanks for help provided