此休息请求的正确标头是什么?

时间:2016-10-24 15:56:44

标签: java php rest curl http-headers

我在java中有一个Rest服务器,它将此作为post方法处理程序

@POST
@Path("{add}")
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void newTodo(@FormParam("id") Integer id, @FormParam("name") String name, @FormParam("mark") Integer mark, @Context HttpServletResponse servletResponse) throws IOException {
    Student student = new Student(name, mark, id);
    StudentDao.instance.getModel().put(id, student);
    servletResponse.sendRedirect("../create_student.html");
}

我正在通过以下

发送请求
$service_url = "http://localhost:8080/RestWS/rest/Students/add";
$curl = curl_init($service_url);
$curl_post_data = array(
        "name" => "juan",
        "mark" => "10",
        "id" => "10"
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_response = curl_exec($curl);
//print_r (curl_getinfo($curl));
//print_r (curl_errno($curl));
//print_r (curl_error($curl));
curl_close($curl);
print_r($curl_response);

我收到HTTP 415 - Unsupported Media Type错误回复,我猜这是标题的问题,但是在尝试了不同的东西并在网上查找之后我什么都没有...我已经尝试用json头,XML / HTML传递它并在服务器上更改mediatype,但我似乎无法正确使用,这是我应该在这里使用的正确的头文件集?

0 个答案:

没有答案