Posting multidimensional array with PHP and CURL

前端 未结 8 2086
难免孤独
难免孤独 2020-11-27 06:29

I\'m having trouble posting form data via CURL to a receiving PHP script located on a different host.

I get an Array to string conversion error

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 06:48

    $post = "ac=on&p=1&pr[]=0&pr[]=1&a[]=3&a[]=4&pl=on&sp[]=3&ct[]=3&s=1&o=0&pp=3&sortBy=date";
    parse_str($post,$fields); 
    
    $url = 'http://example.com/';
    
    
    //open connection
    $ch = curl_init();
    
    //set the url, number of POST vars, POST data
    curl_setopt($ch,CURLOPT_URL, $url);
    curl_setopt($ch,CURLOPT_POST, true);
    curl_setopt($ch,CURLOPT_POSTFIELDS, $fields);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
    
    //execute post
    $result = curl_exec($ch);
    
    //close connection
    curl_close($ch);
    

提交回复
热议问题