I'm struggling to get my head around the encoding of parameters sent to SagePay via cURL. According to their docs all parameters need to be URL encoded. I'm using PHP's urlencode method on my parameters before passing them as a string to SagePay. Here's an example of part of the string:-

$data = "BillingFirstnames=Jos%C3%A9+Luis&BillingSurname=Test" ...

However, it is failing to correctly render the accented "é" on the SagePay Server website:-

Firstname: José

SagePay's docs state that you can pass accented characters as part of the billing first name (etc.) and that the parameter should be URL encoded.

Our cURL request looks something like this (in case this is of help):-

// Set the URL
curl_setopt($cs, CURLOPT_URL, $url);
// No headers, please
curl_setopt ($cs, CURLOPT_HEADER, 0);
// It's a POST request
curl_setopt ($cs, CURLOPT_POST, 1);
// Set the fields for the POST
curl_setopt ($cs, CURLOPT_POSTFIELDS, $data);
// Return it direct, don't print it out
curl_setopt($cs, CURLOPT_RETURNTRANSFER,1); 
// This connection will timeout in 30 seconds
curl_setopt($cs, CURLOPT_TIMEOUT,30); 
curl_setopt($cs, CURLOPT_SSL_VERIFYPEER, FALSE);

$response = preg_split('/$\R?^/m',curl_exec($cs));

Any suggestions on how to resolve this so that the first name appears as "José" on SagePay?

有帮助吗?

解决方案

You can set utf-8 content type through http header. For example:

curl_setopt($cs, CURLOPT_HTTPHEADER, 
    array('Content-Type: application/x-www-form-urlencoded;charset="utf-8"')
);

You've already mentioned about the php urlencode in your question, but I didn't see it on your code. So adding that again too.

$post = "age=15&name=".urlencode("José");
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top