重定向(302)调用后出现404错误

时间:2018-06-30 20:48:43

标签: java http-status-code-302 unirest

@POST
@Path("/testmethod")
@CacheControl(maxAge = 1, maxAgeUnit = TimeUnit.DAYS)
@Produces( MediaType.TEXT_HTML)    
public Response TestMethod() throws AppException, ParserConfigurationException,
                SAXException, NullPointerException, JAXBException, ParseException, InvalidKeyException,
                NoSuchAlgorithmException, NoSuchPaddingException, IOException, UnirestException, ClassNotFoundException{
    cxml = "<payload>dummydetails</payload>";
    signature = "393a4c0990746b221cdb";
    HttpResponse<String> response = Unirest.post("http://www.example.com")
                        .field("payload", cxml)
                        .field("signature", signature)
                        .asString();
    int status = response.getStatus();
    if(status==302) {
        String loc = response.getHeaders().getFirst("Location");
        javax.ws.rs.core.Response.temporaryRedirect(uri).build();
    }
    else {
        String json = XmlUtil.xmlToJson(response.getBody());
                     ob=XmlUtil.jsonToObj(json);
                    JSONObject jsonObject = new JSONObject(json);

                    com.ng.perfiosparams.api.model.response.Error error = XmlUtil.jsonToObj(jsonObject.getString("Error"));
                    if (error.getStatementErrorCode() != null) {
                        ReadXml read = new ReadXml();
                        error.setDescription(read.description(error.getStatementErrorCode()));
                    }
                    error.setResponseType(ResponseType.Error);
                return Response.ok(error).build();    
                }
    }

  

在上面的代码中,我在post调用中得到的响应为302。因此,它将进入 if 条件,在该条件下应从标头重定向到位置网址,但返回404错误。   可能是由于会话过期。你能帮我吗?   预先感谢。

0 个答案:

没有答案
相关问题