2013-04-25 1 views
0

설정이 간단합니다. Joomla 계정이 생성 된 후 데이터베이스 (cURL 게시)를 다른 데이터베이스 지원 응용 프로그램 (MS SQL이 포함 된 ASP)으로 보내는 Joomla 전자 상거래 사이트 (MySQL 백엔드)입니다.cURL 뒤에 공백없이 저장된 데이터

때때로이 데이터는 공백없이 수신 데이터베이스에 저장되는 것이 문제입니다. 예를 들면 : Joomla 사이트에서 수집 된 주소는 "123 example road"으로 데이터베이스에 저장되지만 수신 데이터베이스에는 "123exampleroad"으로 저장됩니다. 이것은 항상 발생하지 않습니다 - 그래서 나는 오히려 그 원인에 대해 당혹 스럽습니다.

누구도 그런 문제가 있습니까? 어떤 도움을 주셔서 감사합니다.

이는 컬 코드 모습입니다 : 하나 개의 매개 변수가 base64를 사용으로 인코딩 된 데이터를 전송하는

//create array of data to be posted 

foreach($registrationfields as $field) { 

if($field->name == 'email') $field->name = 'user_email'; 

if($field->name == 'delimiter_sendregistration') continue; 

if($field->type == 'captcha') continue; 

if($field->type == 'delimiter') continue; 



switch($field->name) { 

    case 'country': 

     require_once(CLASSPATH.'ps_country.php'); 

     $country = new ps_country(); 

     $dbc = $country->get_country_by_code($dbbt->f($field->name)); 

     if($dbc !== false) $val = $dbc->f('country_name'); 

     break; 

    default: 

     $val = $dbbt->f($field->name); 

     break; 

} 



$post_data[$field->name] = $val; 



} 

$post_data['order_id'] = $order_id; 

$post_data['order_date'] = $order_date; 

$post_data['order_status'] = $order_status; 



$post_data['username'] = $username; 



//traverse array and prepare data for posting (key1=value1) 

foreach ($post_data as $key => $value) { 

    $post_items[] = $key . '=' . $value; 

} 



//create the final string to be posted using implode() 

$post_string = implode ('&', $post_items); 



//create cURL connection 

$curl_connection = 

    curl_init('http://--url-here'); 



//set options 

curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30); 

curl_setopt($curl_connection, CURLOPT_USERAGENT, 

    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); 

curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true); 

curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false); 

curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1); 



//set data to be posted 

curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string); 



//perform our request 

$result = curl_exec($curl_connection); 



//show information regarding the request 

print_r(curl_getinfo($curl_connection)); 

echo curl_errno($curl_connection) . '-' . 

       curl_error($curl_connection); 



//close the connection 

curl_close($curl_connection); 

답변

1

이 문제가 해결되었다. 대신 문자열을 형성하기 위해 루프를 한 다음 "내파"를 사용하여 배열을 수정하는 -과 같이 :

//traverse array and prepare data for posting (key1=value1) 
foreach ($post_data as $key => $value) { 
    $post_items[] = $key . '=' . $value; 
} 

//create the final string to be posted using implode() 
$post_string = implode ('&', $post_items); 

내가 오류를 발생시키지 않고 같은 일을 수행하는 대신 " http_build_query"기능을 사용했다.

$post_string = http_build_query($post_data) . "\n"; 
1

보십시오. 네이티브 php 함수는 슬래시와 같은 특수 문자를 출력 할 수 있으므로 사용하지 마십시오. 먼저 대답에 나열된 함수를 this post에 사용하십시오.

curl은 공백 (% 20)을 인코딩하는 방법과 대상 스크립트에서 읽는 방법에 문제가 있다고 생각합니다.

예 (링크에서 함수를 사용하여)는 : I 코드를 다시 고려-후

... 
$post_string = implode ('&', $post_items); 

$post_string = myBase64_encode($post_string); 
... 
+1

공간이 일부 시간에만 올바르게 인코딩/디코딩되는 것은 흥미로운 일입니다. 나는 이것이 어떻게 작동하는지 보게 될 것이다. - 고마워! – Ahmed

+0

다른 상황에서 문자열 인코딩 문제에 대해 많이 알지 못한다는 것을 인정하지만, 개발자가 텍스트를 url param으로 보내는 동안 공백을 피하려고 많은 시간을 보았습니다. 때로는 base64이고 때로는 공백을 "+"기호로 바꿉니다 (다른 방법으로 "+"를 사용하지 않을 것이라고 확신하는 경우) – ex3v

+0

나는 이것을 시도했지만 제대로 작동하지 않았습니다. 왜 그런지 말하기 어렵습니다. – Ahmed