RestAssured.baseURI = url;
Response response = RestAssured.given().contentType(ContentType.XML).body(body).post();
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(url);
org.apache.http.entity.StringEntity entity = new org.apache.http.entity.StringEntity(body);
httpPost.setEntity(entity);
httpPost.setHeader("Accept", "text/xml");
httpPost.setHeader("Content-type", "text/xml");
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity responseEntity = httpResponse.getEntity();
if (responseEntity != null) {
String responseAsString = EntityUtils.toString(responseEntity);
System.out.println(responseAsString);
}This returns an XML response which is correct and the expected response.
What am I doing wrong? Is there some configuration that needs to be made?
--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Request method: POST
Request URI: http://myurl.do/blah
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Multiparts: <none>
Headers: Accept=*/*
Content-Type=application/xml; charset=ISO-8859-1
Cookies: <none>
Body:The XML body that I passedTo unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
Response response = RestAssured.given()
.accept(ContentType.XML)
.contentType(ContentType.XML)
.log()
.all()
.body(body)
.post();Even after that I see the same HTML as response.
Your first statement (the RA way) didn't tell the server what content type you will accept in the response, only what type you are sending in the request.
I have an XML body which needs to be posted to a non-secure url. So I'm doing the following--RestAssured.baseURI = url;
Response response = RestAssured.given().contentType(ContentType.XML).body(body).post();
However The response I receive is an HTML page which is not correct. If I do the same thing as belowHttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(url);
org.apache.http.entity.StringEntity entity = new org.apache.http.entity.StringEntity(body);
httpPost.setEntity(entity);
httpPost.setHeader("Accept", "text/xml");
httpPost.setHeader("Content-type", "text/xml");
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity responseEntity = httpResponse.getEntity();
if (responseEntity != null) {
String responseAsString = EntityUtils.toString(responseEntity);
System.out.println(responseAsString);
}
This returns an XML response which is correct and the expected response.
What am I doing wrong? Is there some configuration that needs to be made?
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
| private static EncoderConfig enConfig = new EncoderConfig(); | ||||||||
| private static RestAssuredConfig rConfig = RestAssuredConfig.config() | ||||||||
| .encoderConfig(enConfig | ||||||||
| .appendDefaultContentCharsetToContentTypeIfUndefined( | ||||||||
false));
|
Found the issue. Thanks for pointing me towards Wireshark.
I compared the request that was sent from RA and request that was sent from HttpClient.So this is what is happening. RA is dropping the query string for some reasons.My URL to POST is http://something.domain.com/com/login.do?site=2HttpClient is sending as is. Which is good. But RA is doing a POST with the following URL
--