PHP CURL Post Fields无效

时间:2016-03-04 13:29:39

标签: php curl

PHP curl post无效..

这是我的代码

Dim options = ConfigHelper.GetContentValue("NavigationPaging", "PageSizeOptions").Split(CChar(","))
Dim optionsList As List(Of Integer) = New List(Of Integer)() 'Initialise the collection here to avoid the For Each
For Each item As String In options
    Dim i As Integer
    If Int32.TryParse(item, i) Then
        optionsList.Add(i)
    End If
Next

你可以查看错误..

代码出错或网站上有什么不同。

2 个答案:

答案 0 :(得分:1)

您可以按原样传递包含字段的数组。尝试

function post_to_url($url, $fields) {
    $post = curl_init($url);

    curl_setopt($post, CURLOPT_POST, true);
    curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
    curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);

    $result = curl_exec($post);

    curl_close($post);
}

答案 1 :(得分:0)

尝试使用此

 $postfields = http_build_query($data);
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL,$url);
 curl_setopt($ch, CURLOPT_POST, true);
 curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);