Cross Domain Proxy : Blank XML returned when url contains space

Discussion in 'PHP' started by swarnendude, Jan 13, 2010.

  1. #1
    Hi All,

    I am using a proxy to retrieve data (in xml format) from a remote server. Depending on a search string, a url is formed : for example, if search string is "hello all", then the url will be :
    
    'http://songbuzz.rediff.com/search/hello all?output=xml'
    Code (markup):
    when this search string is a single string, i am getting proper xml data...but when there are multiple strings, most of the time I am not getting any result - A blank response.

    Following is my proxy code:

    // The actual form action
    $action = $_REQUEST['url'];
    
    // Initiate cURL
    $ch = curl_init();
    
    // Do we need to POST of GET ?
    if (strtoupper($method) == 'POST')
    {
    	curl_setopt($ch, CURLOPT_URL, $action);
    	curl_setopt($ch, CURLOPT_POST, 1);
    	curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);  [I am not using the field attribute]
    }
    else
    {
    	curl_setopt($ch, CURLOPT_URL, $action);
    }
    
    // Follow redirects and return the transfer
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    
    // Get result and close cURL
    $result = curl_exec($ch);
    curl_close($ch);
    
    // Return the response
    header('Content-Type: text/xml'); 
    echo $result;
    Code (markup):

    I tried several other proxies (open source available) but the same thing is happening.
    Can you tell me where am I going wrong?


    Thanks,
    Swarnendu
     
    swarnendude, Jan 13, 2010 IP
  2. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #2
    set your proxy in
    curl_setopt($ch, CURLOPT_PROXY, $proxy);
    Code (markup):
     
    javaongsan, Jan 13, 2010 IP
  3. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #3
    Did you try to urlencode() action url or at least replace spaces with + (plus) sign?
     
    AsHinE, Jan 14, 2010 IP