2009-07-22 7 views
0
$description = "some test data and url"; 
$description .="http://www.mydata.com?test=1&user=4&destination=645&source=stackoverflow"; 

curl_setopt($sch, CURLOPT_URL, "myserverurl"); 
curl_setopt($sch, CURLOPT_HEADER, 0);    
curl_setopt($sch, CURLOPT_POST, true); 
curl_setopt($sch, CURLOPT_RETURNTRANSFER , 1); 
curl_setopt($sch, CURLOPT_POSTFIELDS, "orgid=$orgid&description=$description&external=1"); 
curl_setopt ($sch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt ($sch, CURLOPT_SSL_VERIFYPEER, 0); 

내가 서버 (myserverurl)를 점검 할 때.curl PHP에서 url 값을 전달하는 방법

나는

처럼 "테스트 데이터 및 URL http://www.mydata.com?test=1"을 설명 필드를 볼 수 있습니다.

은 내가 '&'

예, 우리는 컬로 전송하기 전에 URL을 인코딩 할 수 있습니다 후 설명을 잃었지만, 나는 제 3 자의 API를 서버에 다시 URL을 디코딩 할 액세스 권한이없는

+0

, 당신은 설명 필드의 서버에 어떤 값을받을 수 있나요? – FWH

+0

http://us2.php.net/http_build_query –

답변

0

무엇 만약 당신이 urlencode 당신이 보내는거야?

당신은 다른 측면에서 디코딩에 대해 걱정할 필요가 없습니다

: 그것은 GET을 통해 데이터를 전송하는 표준 방법입니다/POST

뭔가 같은 :

curl_setopt($sch, CURLOPT_POSTFIELDS, 
    "orgid=" . urlencode($orgid) 
    . "&description=" . urlencode($description) 
    . "&external=1" 
); 

그리고이 작동하지 않는 경우 , rawurlencode으로 시도 하시겠습니까? (정확하게 기억하면 공백에 차이가 있음)

+2

또는 http://php.net/http_build_query를 사용하면 훨씬 편리합니다. – Salaryman

+1

참으로; 훨씬 더 쉽고/더 쉬웠다. 오류가 발생하기 쉬운 –

0

쉽습니다. 현재 URL이 입력 된 후에 간단히 가져올 수 있습니다.

당신은 입력 그렇다면

http://www.mydata.com?test=1&user=4&destination=645&source=stackoverflow 

(나는 mydata.com가 서버인지, 가정), 당신은 매우 쉽게 에코 할 수 있습니다

$url = str_replace("?","",$_SERVER['REQUEST_URI']); 
echo $url; 

을 그리고 위의 에코 제공해야합니다 :

test=1&user=4&destination=645&source=stackoverflow 

그때부터 전체 문자열을 데이터베이스에 저장하거나 개인을 저장할 수 있습니다. 변수 (테스트, 사용자, 대상, 소스)를 either $_SERVER['test']으로 수정하거나 숫자가 다양 할 경우 & 문자로 분해하여 동적으로 저장할 수 있습니다.

0

게시 용 데이터를 배열에 넣고 해당 배열을 CURLOPT_POSTFIELDS으로 사용하십시오. $_POST['description']에서 설명을 얻을 수 있습니다.


test.php

<?php 
$sch = curl_init(); 
$post_data=array(); 
$orgid='testorg'; 
$description = "some test data and url"; 
$description .="http://www.mydata.com?test=1&user=4&destination=645&source=stackoverflow"; 
$post_data['description']=$description; 
$post_data['orgid']=$orgid; 
$post_data['external']=1; 
curl_setopt($sch, CURLOPT_URL, "localhost/testcurl.php"); 
curl_setopt($sch, CURLOPT_HEADER, 0);    
curl_setopt($sch, CURLOPT_POST, true); 
curl_setopt($sch, CURLOPT_RETURNTRANSFER , 1); 
curl_setopt($sch, CURLOPT_POSTFIELDS, $post_data); 
$re=curl_exec($sch); 

echo('<pre>'); 
echo($re); 

testcurl.php

<?php 
var_dump($_POST); 

결과

array(3) { 
    ["description"]=> 
    string(94) "some test data and urlhttp://www.mydata.com?test=1&user=4&destination=645&source=stackoverflow" 
    ["orgid"]=> 
    string(7) "testorg" 
    ["external"]=> 
    string(1) "1" 
} 
0

이 쉬운 해결책이다.당신이 PHP를 사용 기능 curl_escape()에서 작업하는 경우 당신이 그것을 보내기 전에() URL을 rawurlencode 경우`

$msg=$_POST['Message']; 

$ch = curl_init(); 
$new = curl_escape($ch, $msg); 


$ch = curl_init("url".$new."/xyz.com"); 
$fp = fopen("example_homepage.txt", "w"); 

curl_setopt($ch, CURLOPT_FILE, $fp); 
curl_setopt($ch, CURLOPT_HEADER, 0); 

curl_exec($ch); 
curl_close($ch); 
fclose($fp); 
관련 문제