如何使用PHP Curl发布此类表单?

时间:2015-09-24 22:23:06

标签: php post curl

我正在尝试使用PHP curl发布此类帖子,但我不知道如何发布它,因为这个与我以前发布的不同。

 -----------------------------109944606510290837051636792786
    Content-Disposition: form-data; name="cliente[id]"

    572572
    -----------------------------109944606510290837051636792786
    Content-Disposition: form-data; name="cliente[documento1]"

    154.574.284-78
    -----------------------------109944606510290837051636792786
    Content-Disposition: form-data; name="gender[sexo]"

    feminino
    -----------------------------109944606510290837051636792786
    Content-Disposition: form-data; name="cliente[email]"

    email@example.com
    -----------------------------109944606510290837051636792786
    Content-Disposition: form-data; name="cliente[nome1]"

    Ashley
    -----------------------------109944606510290837051636792786
    Content-Disposition: form-data; name="cliente[nome2]"

    Ivy
    -----------------------------109944606510290837051636792786
    Content-Disposition: form-data; name="endereco[cep]"

    03164-100
    -----------------------------109944606510290837051636792786
    Content-Disposition: form-data; name="endereco[endereco]"

    Rua Example
    -----------------------------109944606510290837051636792786
    Content-Disposition: form-data; name="endereco[numero]"

    123

我尝试这样做,但没有奏效:

 // Post Adicionar ao Carrinho
               $link = "https://www.example.com.br/identificacao/"; 
                $post = "
                -----------------------------109944606510290837051636792786
Content-Disposition: form-data; name="cliente[id]"

572572
-----------------------------109944606510290837051636792786
Content-Disposition: form-data; name="cliente[documento1]"

154.574.284-78
...... "; 
                $s = _curl($link,$post,$cookie);  

我可以发布没有像这样的问题形式:

$post = "comprar%5Bquantidade%5D=1&id_alias=135&client%5Bid_produto%5D=90881&comprar%5Bvariacao%5D=94402"; 

但我不知道那个是什么形式...

1 个答案:

答案 0 :(得分:0)

您发布的示例数据编码为multipart/form-data。为了使curl以此格式发布数据,您需要向CURLOPT_POSTFIELDS数组提供数据。 See Documentation

假设这是$post变量的来源,以下内容应该产生所需的POST:

$post = array(
    'cliente[id]' => '572572',
    'cliente[documento1]' => '154.574.284-78',
    ...
);

$s = _curl($link,$post,$cookie);