suvallur / rest-assured

Automatically exported from code.google.com/p/rest-assured
0 stars 0 forks source link

JSON content is not returned with https POST request #390

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi 

The below code with Rest-assured i am not getting a JSON response.

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.http.ContentType;
import com.jayway.restassured.response.Response;

String logInPayload = "{}" // take any JSON request string.
RestAssured.baseURI = "https:"; // take any https post utl.
JSONObject jsonObject = (JSONObject) jsonParser.parse(logInPayload);
Response resp = RestAssured.given()
            .accept(ContentType.JSON).and()
            .header("Accept", "application/json").and()
            .header("Content-Type", "application/json").and()
            .body(jsonObject.toJSONString()).and()
            .request().relaxedHTTPSValidation().and()
            .when().post(RestAssured.baseURI);

System.out.println(resp.getBody().asString());
System.out.println(resp.contentType());

Out Put as:
<html>
<head><title>401 Authorization Required</title></head>
<body bgcolor="white">
<center><h1>401 Authorization Required</h1></center>
<hr><center>nginx/1.4.7</center>
</body>
</html>

text/html

instead of above text/html i am expecting as json string.

Thanks in advance

Original issue reported on code.google.com by ssireku...@gmail.com on 6 Mar 2015 at 6:48

GoogleCodeExporter commented 9 years ago
Seems like you need to specify some sort of authentication details?

Original comment by johan.ha...@gmail.com on 16 Mar 2015 at 10:51