CURL通过PHP发布

时间:2016-01-16 14:15:02

标签: php xml curl

嗨我需要通过PHP通过POST传递XML来进行curl请求,但我不知道如何做任何人有任何想法?

我现在拥有什么

$xml = '<project>
            ...
            </project>';

    $url = 'http://login:token@localhost:8080/createItem?name=newjobname';
    $fields = array(
        'name' => urlencode('newjobname'),
    );

    $fields_string = 'name=newjobname';

    $ch = curl_init();

    curl_setopt($ch,CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "xmlRequest=" . $xml);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
    $result = curl_exec($ch);

    curl_close($ch);

1 个答案:

答案 0 :(得分:1)

从$ url中删除登录名并将其添加到你的curl:

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "login:token");
相关问题