douzhaxian1267 2015-12-30 08:53
浏览 176
已采纳

错误HTTP状态415 - 将XML从php发送到RESTful时不支持的媒体类型

I have RESTful web service deploy on jboss EAP. In other, I create php file for make a XML and I want send(POST) them to RESTful.

The RESTful http://192.168.0.191:8080/UserManagement/rest/UserService/users/ webservice show like this :

<sample>
  <user>
    <id>1</id>
    <name>Moyes Chuck</name>
    <profession>Teacher</profession>
  </user>
  <user>
    <id>2</id>
    <name>Van Gaal</name>
    <profession>Driver</profession>
  </user>
</sample>

And create postxml.php :

$xml = new SimpleXMLElement('<sample/>');
    $track = $xml->addChild('user');
    $track->addChild('id', "3");
    $track->addChild('name', "Brody Ben");
    $track->addChild('profession', "Manager");

in same file(postxml.php), this code I wrote to post to RESTful:

$service_url1 = 'http://192.168.0.191:8080/UserManagement/rest/UserService/users/';
$curl1 = curl_init($service_url1);
curl_setopt($curl1, CURLOPT_RETURNTRANSFER, true);
$arr=array("key"=>$xml);
curl_setopt($curl1, CURLOPT_POST, 1);
curl_setopt($curl1, CURLOPT_POSTFIELDS,$arr);
echo $curl1_response = curl_exec($curl1);
curl_close($curl1);

But when I run postxml.php on browser http://localhost:82/test3/postxml.php, it show an error :

HTTP Status 415 - Unsupported Media Type.
JBWEB000069: description JBWEB000135: The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.

  • 写回答

2条回答 默认 最新

  • doushan1863 2016-10-08 19:11
    关注

    remove $arr=array("key"=>$xml); and just add this code and will be work fine

    curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
        'Content-Type: application/xml',                                                                                
        'Content-Length: ' . strlen($xml))                                                                       
    ); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题