-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