使用https POST请求不返回JSON内容

时间:2015-03-06 07:37:28

标签: java json rest-assured

以下代码已放心(2.4.0)我没有得到JSON回复。

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 url.
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是:

<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    //second println statement

而不是上面的文字/ html我期待JSON字符串。

预期是:

{
  "message": "No such user with this email",
  "code": "10003"
}

提前致谢

0 个答案:

没有答案