-2
curl -v -X POST -H "Content-Type: application/xml" -d @case.xml --user test:test url
在PHP發送
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_USERPWD, "test:test");
curl_setopt($ch, CURLOPT_POSTFIELDS, ['data' => new CurlFile('case.xml')]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
但是這個代碼不工作,error 400 Bad Request
。
Web服務器使用基本HTTP認證。我使用的是7.0.11
什麼是您的$ URL中包含,是指給我看你的網址是什麼? –
是的,$ url ='http://example.com'; – vladimir
[如何使用PHP curl使用HTTP基本身份驗證進行請求?](http://stackoverflow.com/questions/2140419/how-do-i-make-a-request-using-http-basic -authentication-with-php-curl) – halfer