Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
404重定向(302)post呼叫时出错 @POST @路径(“/testmethod”) @CacheControl(maxAge=1,maxAgeUnit=TimeUnit.DAYS) @生成(MediaType.TEXT\u HTML) 公共响应TestMethod()引发AppException、ParserConfiguration异常、, SAXException、NullPointerException、JAXBEException、ParseException、InvalidKeyException、, NoSuchAlgorithmException、NoSuchPaddingException、IOException、UnirestException、ClassNotFoundException{ cxml=“dummydetails”; 签名=“393a4c0990746b221cdb”; HttpResponse response=Unirest.post(“http://www.example.com") .字段(“有效载荷”,cxml) .字段(“签名”,签名) .asString(); int status=response.getStatus(); 如果(状态==302){ 字符串loc=response.getHeaders().getFirst(“位置”); java.ws.rs.core.Response.temporaryRedirect(uri.build(); } 否则{ 字符串json=XmlUtil.xmlToJson(response.getBody()); ob=XmlUtil.jsonToObj(json); JSONObject JSONObject=新的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); 返回Response.ok(错误).build(); } }_Java_Http Status Code 302_Unirest - Fatal编程技术网

404重定向(302)post呼叫时出错 @POST @路径(“/testmethod”) @CacheControl(maxAge=1,maxAgeUnit=TimeUnit.DAYS) @生成(MediaType.TEXT\u HTML) 公共响应TestMethod()引发AppException、ParserConfiguration异常、, SAXException、NullPointerException、JAXBEException、ParseException、InvalidKeyException、, NoSuchAlgorithmException、NoSuchPaddingException、IOException、UnirestException、ClassNotFoundException{ cxml=“dummydetails”; 签名=“393a4c0990746b221cdb”; HttpResponse response=Unirest.post(“http://www.example.com") .字段(“有效载荷”,cxml) .字段(“签名”,签名) .asString(); int status=response.getStatus(); 如果(状态==302){ 字符串loc=response.getHeaders().getFirst(“位置”); java.ws.rs.core.Response.temporaryRedirect(uri.build(); } 否则{ 字符串json=XmlUtil.xmlToJson(response.getBody()); ob=XmlUtil.jsonToObj(json); JSONObject JSONObject=新的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); 返回Response.ok(错误).build(); } }

404重定向(302)post呼叫时出错 @POST @路径(“/testmethod”) @CacheControl(maxAge=1,maxAgeUnit=TimeUnit.DAYS) @生成(MediaType.TEXT\u HTML) 公共响应TestMethod()引发AppException、ParserConfiguration异常、, SAXException、NullPointerException、JAXBEException、ParseException、InvalidKeyException、, NoSuchAlgorithmException、NoSuchPaddingException、IOException、UnirestException、ClassNotFoundException{ cxml=“dummydetails”; 签名=“393a4c0990746b221cdb”; HttpResponse response=Unirest.post(“http://www.example.com") .字段(“有效载荷”,cxml) .字段(“签名”,签名) .asString(); int status=response.getStatus(); 如果(状态==302){ 字符串loc=response.getHeaders().getFirst(“位置”); java.ws.rs.core.Response.temporaryRedirect(uri.build(); } 否则{ 字符串json=XmlUtil.xmlToJson(response.getBody()); ob=XmlUtil.jsonToObj(json); JSONObject JSONObject=新的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); 返回Response.ok(错误).build(); } },java,http-status-code-302,unirest,Java,Http Status Code 302,Unirest,在上面的代码中,我在post调用中得到的响应是302。所以,它将进入if条件,在该条件下,它应该从标头重定向到位置url,但返回404错误。 可能是由于会话已过期。你能帮我做这个吗? 提前谢谢 在if中没有返回值,并且没有告诉我们变量uri是什么。看起来您还是想使用变量loc。尽管如此,您还是应该集中精力使您的示例完整、可验证(我们也可以运行它并看到您所遇到的相同问题)和最小化(if之外的所有内容都完全无用,为什么在您处理问题时它仍然存在?)URI-URI=UriBuilder.fromUri(

在上面的代码中,我在post调用中得到的响应是302。所以,它将进入if条件,在该条件下,它应该从标头重定向到位置url,但返回404错误。 可能是由于会话已过期。你能帮我做这个吗? 提前谢谢


在if中没有返回值,并且没有告诉我们变量uri是什么。看起来您还是想使用变量loc。尽管如此,您还是应该集中精力使您的示例完整、可验证(我们也可以运行它并看到您所遇到的相同问题)和最小化(if之外的所有内容都完全无用,为什么在您处理问题时它仍然存在?)URI-URI=UriBuilder.fromUri(loc.build();这一行代码将添加到字符串loc行之后。不要抛出随机行,在同一位置显示完整的示例。还要努力使其完整、可验证和最小化。如果需要,请编辑您的问题。问题应该尽可能的好,而你的问题则不然,所以你应该修改它,并且只有在它被修改好之后才能避免修改。
@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();    
                }
    }