2012-05-17 3 views
0

PHP를 사용하는 cURL에 대해 다음 코드가 있습니다.cURL 응답은 200이지만 실제로 값을 게시하지 않습니다.

$product_id_edit="Playful Minds (1062)"; 
$item_description_edit="TEST"; 
$rank_edit="0"; 
$price_type_edit="2"; 
$price_value_edit="473"; 
$price_previous_value_edit="473"; 
$active_edit="1"; 
$platform_edit="ios"; 

//set POST variables 
$url = 'https://www.domain.com/adm_test/phpgen/offline_items.php?operation=insert'; 
$useragent = 'Mozilla/5.0 (Windows NT 6.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1'; 

$fields = array(
    'product_id_edit'=>urlencode($product_id_edit), 
    'item_description_edit'=>urlencode($item_description_edit), 
    'rank_edit'=>urlencode($rank_edit), 
    'price_type_edit'=>urlencode($price_type_edit), 
    'price_value_edit'=>urlencode($price_value_edit), 
    'price_previous_value_edit'=>urlencode($price_previous_value_edit), 
    'active_edit'=>urlencode($active_edit), 
    'platform_edit'=>urlencode($platform_edit) 
); 

$fields_string=""; 

//url-ify the data for the POST 
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } 
rtrim($fields_string,'&'); 

//open connection 
$ch = curl_init(); 

//set the url, number of POST vars, POST data 
curl_setopt($ch, CURLOPT_VERBOSE, 1); 
curl_setopt($ch,CURLOPT_URL,$url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
//add useragent 
curl_setopt($ch, CURLOPT_USERAGENT, $useragent); 

curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); 

curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); 
curl_setopt($ch,CURLOPT_POST,count($fields)); 

//execute post 
$result = curl_exec($ch); 
if(curl_errno($ch)){ 
print "" . curl_error($ch); 
}else{ 
//print_r($result); 
} 

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
//echo "HTTP Response Code: " . curl_error($ch); 
echo $httpCode; 

//close connection 
curl_close($ch); 

나는 $ httpCode를 인쇄했습니다. 나는 코드 200을 얻는다; 나는 수동 페이지에서 읽었으므로 OK입니다. 그러나 사이트를 점검 할 때 게시 된 값은 존재하지 않습니다.

게시자가 아니기 때문에 도메인 간 관련이 있습니다. 127.0.0.1/site/scrpt.php에서이 작업을 수행하고 있지만 성공하지 못하면 어떻게 응답 코드 200을 얻을 수 있습니까?

나는 또한 함께 URL https://www.domain.com/adm_test/phpgen/offline_items.php?operation=insert을 가지고 있습니까 나는 그것이

(이 컬을 내 가정에서 제대로 작동하고 있음을 의미합니다) 404를 반환 한 요청 URL에 일부를 제거하여 한 404을 얻기 위해 노력 "? operation = insert"는 그것과 관련이 있습니까?

다른 사이트의 게시물이고 다른 웹 사이트 형식의 값인 post'a 로봇을 사용한다고 가정 해 봅시다. tho 내 목표는 악의적 인 의도를 암시하지 않는다. 이것이 가능하지 않다면 나는 천 라인의 정보를 암호화해야만한다.

마찬가지로, 나는 서버의 응답이 필요하지 않습니다 (하지만 하나가 가능한 다음의 잘 경우)

+1

왜 이것을 javascript 및 jQuery로 태그 지정 했습니까? –

답변

0

작업은 CURLOPT_POSTFIELDS와 함께 전달되어야한다. 다른 매개 변수와 함께.

브라우저의 경우 도메인 간 문제가 발생합니다. 그리고 귀하의 코드는 PHP 서버 측 코드로 보이므로 문제가되지 않아야합니다. 부울,이 카운트 아니다 -

$fields_string = rtrim($fields_string,'&'); 
0

확실하지 않음 가치의 그것, 사용 포스트 깃발이다.

코드 200은 연결이 올바르게 설정되었고 서버로부터 응답을 받았음을 나타내지 만 요청한 조치가 구현되었음을 의미하지는 않습니다.

인쇄 $result 웹 서버에서 응답을 요청한 후.

0
curl_setopt($ch,CURLOPT_POST,TRUE); 

CURLOPT_POST :

rtrim($fields_string,'&'); 

이이어야한다 :이 솔루션 또는 문제가 다르지만,이 줄 경우

+0

내 로컬 xampp 홈 페이지를 표시하는 응답 결과로 http://127.0.0.1/xampp/가 표시됩니다. 맞습니까? POST 값이 통과되지 않은 웹 사이트를 확인했습니다. –

+0

'https : // www.domain.com/etc/etc'을 요청하여 로컬 페이지를 받고 있습니까? – ShaaD

+0

예! 그게 이해하기 어렵게 만든 바로는 ... –

관련 문제