将JSON请求发送到uservoice

时间:2012-05-17 07:16:39

标签: php jsonp uservoice

我目前正在使用联系我们表单将用户信息发送到uservoice。我正在使用jquery代码将json请求发送到uservoice。

以下是代码:

$('#test_form').submit(function(evt) {

    evt.preventDefault();  



    var uvSubdomain = "initech";/



    var uvKey = "5JVoVrAGdl4pMkcEkIeIDA";




    var message = $('#message').val();

    var subject = $('#subject').val();

    var name = $('#name').val();

    var email = $('#email').val();



    $.jsonp({

        url: 'https://' + uvSubdomain + '.uservoice.com/api/v1/tickets/create_via_jsonp.json\\?callback=?',

        data: {

            client: uvKey,
            ticket: {
                message: message,
                subject: subject
            },
            name: name,
            email: email
        },

        success: function(data) {

            alert('Successfully submitted ticket!');  // You might want to redirect the user here, or show a stylized message to them.

        },

        error: function(d, msg) {

            alert("Error"); 

        }

    });

    return false;
});

现在我希望在PHP的帮助下发送json请求。

如果您对此有任何建议或代码,请与我们联系。

谢谢你

1 个答案:

答案 0 :(得分:0)

您可以使用curl扩展名:

$c = curl_init();
curl_setopt($c, CURLOPT_URL, 'https://test.com');
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, 'name1=value1&name2=value2'); //post data
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($c);
curl_close($c);

如果您连接到https网站,则必须添加以下内容之一:

//easy solution
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);

//secure solution
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($c, CURLOPT_CAINFO,"/path_to_certificate/cert.crt");