angelleye Posted June 3, 2007 Share Posted June 3, 2007 I've got the following: <?php $url = "my_url"; $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_USERPWD, "my_username:my_password"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, $url); $xmlResponse = curl_exec($ch); curl_close($ch); ?> The response I'm getting back is simply: <h1>Bad Request</h1> When I type my_url directly into a web browser a un/pw dialog pops up and when i use my_username and my_password it displays the XML on the screen as expected. Also, I have an ASP script that is currently working just fine hitting this same URL with the same credentials. Any information on what I'm doing wrong with my PHP/CURL would be greatly appreciated. Thanks! Link to comment https://forums.phpfreaks.com/topic/54093-solved-trouble-with-curl-and-http-authentication/ Share on other sites More sharing options...
TripleDES Posted June 3, 2007 Share Posted June 3, 2007 Try not using CURLOPT_POST and also try CURLOPT_URL, "$url". I'm looking at your example and the one I have working and there's not much of a difference. Here's mine: $curl = curl_init(); curl_setopt ($curl, CURLOPT_URL, "$url"); curl_setopt($curl, CURLOPT_USERPWD, "user:pass"); curl_setopt($curl, CURLOPT_USERAGENT, $useragent); //Spoofs Firefox curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec ($curl); curl_close ($curl); Link to comment https://forums.phpfreaks.com/topic/54093-solved-trouble-with-curl-and-http-authentication/#findComment-267446 Share on other sites More sharing options...
TripleDES Posted June 3, 2007 Share Posted June 3, 2007 And if you haven't already visited: http://hudzilla.org/phpwiki/index.php?title=Introduction_to_Curl Link to comment https://forums.phpfreaks.com/topic/54093-solved-trouble-with-curl-and-http-authentication/#findComment-267447 Share on other sites More sharing options...
angelleye Posted June 3, 2007 Author Share Posted June 3, 2007 I made changes to match yours and I'm getting the same Bad Request string returned. Link to comment https://forums.phpfreaks.com/topic/54093-solved-trouble-with-curl-and-http-authentication/#findComment-267452 Share on other sites More sharing options...
angelleye Posted June 3, 2007 Author Share Posted June 3, 2007 It didn't like me adding the querystring paramaters onto the $url string. I removed them from that and added them to a $postFields string which I then included with CURLOPT_POSTFIELDS. $url = "http://www.domain.com"; $postFields = "Param1=Val1&Param2=Val2"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERPWD, "username:password"); curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); $xmlResponse = curl_exec($ch); And that is working now. I guess it might have helped if I'd have included those details in my original post! Doh! Link to comment https://forums.phpfreaks.com/topic/54093-solved-trouble-with-curl-and-http-authentication/#findComment-267459 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.