泽西岛-405方法不允许

时间:2018-09-25 12:48:54

标签: java rest jersey http-status-code-405

我是Web服务的新手。我有一个工作的端点,如果正确告知了参数(标识符和密码),它会向我返回一个包含人员数据的JSON。

像这样:

http://www.issdigitalthe.com.br/controleacesso/servico/api/login/4/SMT/000000000000/password/false

其中000000000000是我的标识符,“ password”是我的密码。

使用PostMan(POST)进行测试,这是我的回报:

"id": 40001002131,
    "idOriginal": 123131,
    "cpfCnpj": "000000000",
    "nome": "JOHN DOE",
    "idCargo": 131313131,
    "descricaoCargo": "Usuário responsável por analisar e Deferir/Indeferir os Protocolos.",
    "idDepartamento": 4000200000000761,
    "descricaoDepartamento": "Departamento para usuários ",
    "login": "000000000",
    "email": "john@gmail.com",
    "ultimoAcesso": 1537824078846,
    "certificadoDigital": "N",
    "dataCriacao": null,
    "bairro": "Bairro",
    "cep": "64020340",
    "complemento": "Quadra 00 Casa 111",
    "dddCelular": "86 ",
    "dddTelefone": "86 ",
    "celular": "99999999",
    "telefone": "86 ",
    "uf": "PI",
    "municipio": "SÃO PAULO",

我必须使用该服务来检查退货是否有效。 这是我的代码:

import javax.faces.bean.ManagedBean;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;

@Path("/")
@ManagedBean
public class WebServiceLoginMB {

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON + MediaType.TEXT_HTML)

    public String getDados() {
        Client c = Client.create();
        WebResource wr = c.resource("//www.issdigitalthe.com.br/controleacesso/servico/api/login/4/SMT/000000000000/password/false);
        return wr.get(String.class); 
      }
}

起初,我只是想在我的Glassfish控制台上查看退货,然后我将检查退货是否正确。但我总是 “返回的响应状态为405方法不允许”。

它是这样工作的:

    public static void ws(String user, String pass) {

        try {

            Client client = Client.create();
            WebResource webResource = client.resource(
"http://www.issdigitalthe.com.br/controleacesso/servico/api/login/4/SMT/"+ user + "/"+ pass + "/false");
            ClientResponse response = webResource.type("application/json").post(ClientResponse.class);

            String output = response.getEntity(String.class);
            Gson gson = new Gson();
            PessoaNota pessoa = gson.fromJson(output, PessoaNota.class);
            System.out.println(pessoa.getNome());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

我知道它仍然需要调整,但是第一个问题已解决。感谢所有提供帮助的人。

1 个答案:

答案 0 :(得分:0)

由于执行HTTP GET调用而收到此错误,而在邮递员中您尝试了HTTP POST。尝试像这样发帖

public String getDados() {
    Client c = Client.create();
    WebResource wr = c.resource("http://www.issdigitalthe.com.br/controleacesso/servico/api/login/4/SMT/000000000000/password/false);
    return wr.post(String.class); 
  }