Consume WebService

0

Hello, I have a link from a service link that when accessed via web browser, asks me for login and password and I get result in json (only after entering username and password).

"field": "given";

I would like help writing a page, perhaps in javascript, to consume this webservice. I am having trouble passing basic http authentication. Any link and / or suggestion of what to look for and / or where to start?

    
asked by anonymous 17.07.2017 / 04:10

1 answer

0
$a='stringsearch';
$username = 'username';
$password = 'password';
$url = "http://exemplo.meuwebservice:(porta)/paraexemplo/$a";

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, "Accept: application/json" );


$output = curl_exec($ch);
$info = curl_getinfo($ch);


curl_close($ch);

$obj = json_decode($output);
$json_output = json_decode($output, true);
foreach($json_output as $item){
    foreach($item as $dados){
    echo $dados;
    }
}
    
20.08.2017 / 16:31