由于某种原因,当我尝试使用响应正文的打印语句打印响应时,系统不打印。请帮忙。
在下面的 API 帖子中,我在 Eclipse Neon 3 上使用 Java、放心的 TestNG。使用 @DataProvider 注释,我在 Post 请求中传递多个参数以查看调用的响应。任何帮助将不胜感激。
package com.auto.restassured;
import io.restassured.RestAssured;
import static io.restassured.RestAssured.basic;
import static io.restassured.RestAssured.given;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import io.restassured.response.Response;
import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;
public class FilePostToVirusTotal {
static String baseURL = "https://www.virustotal.com/vtapi/v2/file/report";
Response myResponse;
@DataProvider(name = "md5hashes")
public String[][] createMd5Hashes() {
return new String[][] {
{"md51", "c1105fb75bc00b5e487f7b26a5be7088"},
{"md52", "213f3287c81d09b095334c9f3151cff8"},
{"md53", "b00c2c458b4cf1eb172e354f54f0fe12"},
{"md54", "32ac9b6b6b7cdbfce179acc5edae98c3"},
{"md55", "510b0b81b85c025d538ed4bad78dc64f"},
};
}
@Test(dataProvider = "md5hashes")
public void md5JsonTest(String apikey, String resource)
{
//Catch API response
myResponse = given().param("text", resource).param("text", "34b937e6e2d28ee6f93a70392d958de8ac4a8dd842e08bbca9bcb0d22f9b9960").when().post(baseURL);
//Print Response
System.out.println(myResponse.getBody().asString());
}
}
最佳答案
您可以使用内置的日志方法,例如given().log().all()
用于请求,then().log().all()
用于响应
关于java - 无法在控制台上打印 api 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44351824/