Consumir Webservice

Asked

Viewed 226 times

0

Hello, I have a service link http://example.meuwebservice:(port)/paraexample/ that when accessing via web browser, asks me for login and password and can result in json (only after entering username and password).

"field":"" ;

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

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;
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.