• 03-11-2012, 20:29:14
    #1
    Üyeliği durduruldu
    Curl ile json post etmek istiyorum. Çok fazla yöntem denememe rağmen başarılı olamadım. Nasıl yapılır curl ile json post.
  • 03-11-2012, 21:00:20
    #2
    Kimlik doğrulama veya yönetimden onay bekliyor.
    Curl ile normal posttan bir farkı yok. Sadece header olarak

    Content-Type: application/json
    göndereceksin ve datayı göndermeden json_encode yapacaksın o kadar.

    google da bir sürü örnek bulabilirsin.
  • 03-11-2012, 22:05:53
    #3
    Üyeliği durduruldu
    Kaynak kodlarım bunlar karşıdaki php dosyasından veri alamıyorum. Nerede ne gibi düzeltme yapmam gerekiyor ? Yardımcı olursan sevinirim.

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4");
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
    curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
    $postfields = array("cmd"=>$cmd,"parent"=>$parent,"key"=>$key);                                              
    $data_string = json_encode($postfields); 
    curl_setopt($ch, CURLOPT_URL, "http://site.com/post.php"); 
    curl_setopt($ch, CURLOPT_POST, 1);                                                                 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);  
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));                                                                
    $data = curl_exec($ch);

    var params={
    						cmd		: 'blist',
    						parent	: 12189,
    						key		: '70ee439586c0615b5bb4ffe47eadb469'
    					};
    
    $.post('post.php',params,function(json)
    						{
    							if(json.success)
    							{
    								$('#yaz').html(json.results);
    							}
    							else
    							{
    								alert(json.messages);
    							}
    						}, 'json');
  • 03-11-2012, 23:01:00
    #4
    Üyeliği durduruldu
    bu şekil dene

    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($data_string))
    );
  • 04-11-2012, 00:53:50
    #5
    Üyeliği durduruldu
    fayda yok yine aynı.