无法在控制台上打印API响应 [英] Cannot print api response on console

查看:82
本文介绍了无法在控制台上打印API响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某些原因,当我尝试使用针对响应正文的print语句打印响应时,系统无法打印.请帮忙.

For some reason, when I try to print the response using print statement for the response body, the system does not print. please help.

在下面的API帖子中,我在Eclipse Neon 3上使用Java(确保放心),TestNG.使用@DataProvider批注,我在Post请求中传递了多个参数以查看调用的响应.任何帮助将不胜感激.

In the following API post, I am using Java, rest-assured, TestNG on Eclipse Neon 3. Using @DataProvider annotation, I am passing multiple params in Post request to see the response of the call. Any help would be truly appreciated.

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()用于响应

You can use built-in log methods e.g. given().log().all() for request and then().log().all() for response

这篇关于无法在控制台上打印API响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆