PHP Developers Network
http://forums.devnetwork.net/

Help with get request in Json format 2
http://forums.devnetwork.net/viewtopic.php?f=13&t=144979
Page 1 of 1

Author:  sjuaq [ Fri Dec 15, 2017 4:09 pm ]
Post subject:  Help with get request in Json format 2

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?

Quote:
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/search?key=CevVNIYrV6gUzMoxiMhcaO3JIJOmpCY1&facets=&query=xampp", true);
xmlhttp.send();
</script>


Thanks
I'm a noob i know. If possible include a few references/examples to how Json works.

Author:  requinix [ Fri Dec 15, 2017 4:25 pm ]
Post subject:  Re: Help with get request in Json format 2

myObj.matches is an array, not an object. Use a loop.

Author:  sjuaq [ Sat Dec 16, 2017 6:38 am ]
Post subject:  Re: Help with get request in Json format 2

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?
Quote:
<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?)

Author:  requinix [ Sat Dec 16, 2017 7:54 am ]
Post subject:  Re: Help with get request in Json format 2

setRequestHeader() goes after open() and before send(), but otherwise yes.

Author:  sjuaq [ Sat Dec 16, 2017 1:54 pm ]
Post subject:  Re: Help with get request in Json format 2

Quote:
<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

Author:  requinix [ Sat Dec 16, 2017 6:42 pm ]
Post subject:  Re: Help with get request in Json format 2

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.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/