Cannot print api response on console

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Cannot print api response on console

Pullabhotla Srinivas

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

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 greatly appreciated.


Here is the code :


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());

}
}



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/1431f048-0b41-4835-97db-2440135cca9f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cannot print api response on console

⇜Krishnan Mahadevan⇝

Please help keep this forum relevant by posting queries that are ONLY related to Selenium/WebDriver.

Your question is not related to Selenium/WebDriver. You might want to post this query on a Rest-assured related forum.

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

 

From: <[hidden email]> on behalf of Pullabhotla Srinivas <[hidden email]>
Reply-To: <[hidden email]>
Date: Sunday, June 4, 2017 at 1:42 PM
To: Selenium Users <[hidden email]>
Subject: [selenium-users] Cannot print api response on console

 

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

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 greatly appreciated.

 

Here is the code :

 

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());
 
}
}

 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/1431f048-0b41-4835-97db-2440135cca9f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/03688394-2311-4ECD-BF39-3A7E88107294%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cannot print api response on console

Doug Dragon
In reply to this post by Pullabhotla Srinivas
You may find what you're looking for in this SO thread: https://stackoverflow.com/a/26488661/2573711

On Sunday, June 4, 2017 at 10:42:27 PM UTC-4, Pullabhotla Srinivas wrote:

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

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 greatly appreciated.


Here is the code :


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 = "<a href="https://www.virustotal.com/vtapi/v2/file/report" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.virustotal.com/vtapi/v2/file/report&#39;;return true;" onclick="this.href=&#39;https://www.virustotal.com/vtapi/v2/file/report&#39;;return true;">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());

}
}



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/395886cf-0d7a-45a2-8017-1f19fd3b7f4f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...