0

I have been given an IP address where the access is restricted via the .htaccess and requires user login via the prompt. However, this needs to be automated as there is an API on that IP which I need to access - is there a way I can send the username and password via the URL?

eg. I access the API via (space after "//" doesn't exist in real code): http:// 118.118.1.118/API/query I've tried making the URL like this http:// username:password@118.118.1.118/API/query, but it didn't work - I get failed auth. I tested on IE.

Any ideas?

GuitarMan
  • 89
  • 1
  • 10
  • Wich method do you use to get the reponse? If you are using php, you can use Curl, or you can also use Curl from CLI: http://www.electrictoolbox.com/php-curl-sending-username-password/ Username and passwords are not valid in the URL – vaso123 Oct 27 '14 at 14:49
  • use Curl. How to is answered here http://stackoverflow.com/questions/21411754/curl-provide-user-and-password-for-apache-htaccess-file – Maarten Venema Oct 27 '14 at 14:52
  • I'm using file_get_contents. So if I did this: `$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); $output = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch);` I would then use the $output to process the JSON? – GuitarMan Oct 27 '14 at 15:07

0 Answers0