Joey Hipolito
Joey Hipolito

Reputation: 3166

Cross domain posting using a proxy

This works, certainly but when I add parameters it doesn't

<?php
    //set POST variables
    $url = $_POST['url'];
    unset($_POST['url']);
    $fields_string = "";
    //url-ify the data for the POST
    foreach($_POST as $key=>$value) {
            $fields_string .= $key.'='.$value.'&';
    }
    $fields_string = rtrim($fields_string,'&');
    //open connection
    $ch = curl_init();
    //set the url, number of POST vars, POST data
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_POST, 1);
    curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
    //execute post
    $result = curl_exec($ch);
    //close connection
    curl_close($ch);

When I tried ajax calls using jquery,

        var data = "url=http://www.domain/ajax/set.php&id=1413&index=0&action=add";
        $.ajax({
            url: "proxy.php",
            data: data,
            type: "POST",
            success: function(data, textStatus, jqXHR) {
                console.log('Success ' + data);

            },
            error: function(jqXHR, textStatus, errorThrown) {
                console.log('Error ' + jqXHR);
            }
        });

That should return null or "selected" . . . selected if successful on the first run and tried to run again, but both return null, excluding the success word of course.

I'm pretty sure that the params are correct, I used postman to check.

Upvotes: 1

Views: 570

Answers (1)

M8R-1jmw5r
M8R-1jmw5r

Reputation: 4996

set.php&id=1413
       ^

Did you mean?

set.php?id=1413
       ^

Upvotes: 1

Related Questions