PHP RESTful不支持的媒体类型错误

时间:2014-05-02 08:53:36

标签: java php curl restful-authentication glassfish-4

enter image description here我认为它提供了比以前更好的表现。新的发展是虽然它没有插入,但至少它发出了一个可以理解的错误" Unsupported Media Type"而不是像以前那样显示代码。

我该怎么做才能纠正这个错误?我认为这是因为我没有添加内容类型,添加后它会产生相同的结果。我仍然在localhost上运行两个服务器。

使用Java在Netbeans中创建Web服务,而使用在XAMPP下运行的PHP创建调用应用程序。有关错误报告的概述,请参阅附图。

<?php

  if (!empty($_POST['username']) && !empty($_POST['username'])) {
    $username = $_POST['username'];
    $password = $_POST['password'];

    $url = "http://localhost:8080/WMWS/webresources/entity.userregistration";

    $data = array('username' => $username, 'password' => $password);
   $initializeCurl = curl_init();
   curl_setopt($initializeCurl, CURLOPT_HTTPHEADER, array(
        'method' => "POST",
        'Content-type' => "text/plain"
        ));
   curl_setopt($initializeCurl, CURLOPT_URL, $url);
   curl_setopt($initializeCurl, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($initializeCurl, CURLOPT_POST, true);
   curl_setopt($initializeCurl, CURLOPT_POSTFIELDS, $data);
   $response = curl_exec($initializeCurl);
   var_dump($response);  // string(37) "{"username":"test","password":"test"}"
   curl_close($initializeCurl);
 }

 ?>

  <body>
      <form method = "POST">
          <label for = "username">Username</label>
          <input type = "text" name = "username" />
          <label for = "password">Password</label>
          <input type = "password" name = "password" />
          <button id = "register" name = "register">Register</button>
      </form>
  </body>

0 个答案:

没有答案