call another url using curl in php
<p>I am using php cURL for accessing http api..but i got 400 BAD REQUEST.. Your browser sent an invalid request.
and i used following code..</p>

<pre><code>&lt;?php
function get_url( $url,  $javascript_loop = 0, $timeout = 5 ){
    $url = str_replace( "&amp;amp;", "&amp;", urldecode(trim($url)) );
    // $cookie = tempnam ("/tmp", "CURLCOOKIE");
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1;rv:1.7.3) Gecko/20041001 Firefox/0.10.1" );
    curl_setopt( $ch, CURLOPT_URL, $url );
    //curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie );
    // curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
    curl_setopt( $ch, CURLOPT_ENCODING, "" );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );    # required for https urls
    curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
    curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout );
    curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );
    $content = curl_exec( $ch );
    $response = curl_getinfo( $ch );
    curl_close ( $ch );

    if ($response['http_code'] == 301 || $response['http_code'] == 302){
        ini_set("user_agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1");
        if ( $headers = get_headers($response['url']) ){
            foreach( $headers as $value ){
                if ( substr( strtolower($value), 0, 9 ) == "location:" )
                    return get_url( trim( substr( $value, 9, strlen($value) ) ) );
            }
        }
    }

    if ( ( preg_match("/&gt;[[:space:]]+window\.location\.replace\('(.*)'\)/i", $content, $value) || preg_match("/&gt;[[:space:]]+window\.location\=\"(.*)\"/i", $content, $value) ) &amp;&amp;
    $javascript_loop &lt; 5
    ){
        return get_url( $value[1], $javascript_loop+1 );
    } else {
        return array( $content, $response );
    }
}
$name="Bhupesh";
$companyname="Fox Mind IT Solution";
$username="bhupeshparab8@gmail.com";
$password="cricket123";
$address="andheri";
$city="mumbai";
$state="Maharashtra";
$country="India";
$zipcode="400093";
$phonecc="91";
$mob="9870061724";
$lang="en"; 
$str=get_url("https://httpapi.com/api/customers/signup.xml?auth-userid=361983&amp;auth-password=1234@foxmind&amp;username=".$username."&amp;passwd=".$password."&amp;name=".$name." &amp;company=".$companyname."&amp;address-line-1=".$address."&amp;city=".$city."&amp;state=".$state."&amp;country=".$country."&amp;zipcode=".$zipcode."&amp;phone-cc=".$phonecc."&amp;phone=".$mob."&amp;lang-pref=".$lang."");
var_dump($str[0]);

?&gt;
</code></pre>

<p>Please help me on that..and explain me my mistake so i can learn from it..please
Thanks in advance..</p>
