У меня есть простой Java REST WebService -Вызов Java WebService с помощью Python просит
@GET
@Path("/get1")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Status getstudent(Track track) {
System.out.println("GET1 title = " + track.getTitle());
System.out.println("GET1 singer = " + track.getSinger());
Status status = new Status();
status.setStatus_flag("success");
return status;
}
Track
public class Track {
String title;
String singer;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getSinger() {
return singer;
}
public void setSinger(String singer) {
this.singer = singer;
}
@Override
public String toString() {
return "Track [title=" + title + ", singer=" + singer + "]";
}
}
модуль запроса Python: -
import requests
title = {"title":"Best Songs","singer":"lucky"}
r = requests.get("http://localhost:8080/StudentService/rest/insert/get1",data=title)
print r.content
Ошибка
<html><head></head><body>
<h1>HTTP Status 415 - Unsupported Media Type</h1>
<HR size="1" noshade="noshade">
<p><b>type</b> Status report</p>
<p><b>message</b> <u>Unsupported Media Type</u></p>
<p><b>description</b>
<u>The server refused this request because the request entity is
in a format not supported by the requested resource for the requested
method.
</u>
</p>
<HR size="1" noshade="noshade"><h3>Apache Tomcat/6.0.41</h3>
</body></html>
Есть ли способ создать объект сущности и отправить его?
Я попробовал, что и он не работает ... – user1050619
@ user1050619: ожидать ли ваш сервис Java запрос JSON тогда? –
Да, он ожидает запрос JSON. Теперь я редактировал веб-метод @consumes (чтобы принимать только запрос JSON) ... Все еще не работает – user1050619