我在我的Java应用程序中使用org.apache.http.HttpResponse
类,需要能够获取HTTP状态码。如果我对它使用.toString()
,我可以在其中看到HTTP状态码。是否有其他函数可以直接获取HTTP状态码作为int或String?
非常感谢!
我在我的Java应用程序中使用org.apache.http.HttpResponse
类,需要能够获取HTTP状态码。如果我对它使用.toString()
,我可以在其中看到HTTP状态码。是否有其他函数可以直接获取HTTP状态码作为int或String?
非常感谢!
我使用 httpResponse.getStatusLine().getStatusCode()
并发现它可靠地返回整数形式的HTTP状态码。
httpResponse.getStatusLine().getStatusCode()
final String enhancementPayload ="sunil kumar";
HttpPost submitFormReq = new HttpPost("https://bgl-ast/rest/service/form/form-data");
StringEntity enhancementJson = new StringEntity(enhancementPayload);
submitFormReq.setEntity(enhancementJson);
submitFormReq.setHeader("Content-Type", "application/xml");
HttpResponse response = httpClient.execute( submitFormReq );
String result = EntityUtils.toString(response.getEntity());
System.out.println("result "+result);
assertEquals(200, response.getStatusLine().getStatusCode());