我目前正在使用一个联系我们的表单,它将用户信息发送到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请求。
如果你对此有任何建议或代码,请让我知道。
谢谢你
发布于 2012-05-17 15:48:05
您可以使用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");https://stackoverflow.com/questions/10631451
复制相似问题