0

When I'm passing the headers in the first API call, the same header is getting passed again in the second API call. I want to remove all the headers which I passed in the first API call because I don't need those headers in the second API call.

package org.Selenium.testing;

import static io.restassured.RestAssured.given;

import org.testng.Assert;
import org.testng.annotations.Test;

import io.restassured.RestAssured;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;

public class REst {

RequestSpecification requestSpec = RestAssured.given(); 
    private String client_id = "id";
    private String client_secret = "secret";
    private String grant_type = "password";
    private String Username = "a.com";
    private String password = "b";
    private String scope = "x";
    
    @Test
    public void token()
    {
    requestSpec.baseUri("URL1");

    requestSpec.contentType("multipart/form-data")
    .multiPart("client_id", client_id)
    .multiPart("client_secret", client_secret)
    .multiPart("grant_type", grant_type)
    .multiPart("Username", Username)
    .multiPart("password", password)
    .multiPart("scope", scope);
    
    Response response = requestSpec.get();
        
    Assert.assertTrue(response.statusCode()==200);
    response.prettyPrint();
    String token = "Bearer "+response.path("access_token");
    
    System.out.println("------------------- 1st  TC is working---------------------");
    
    requestSpec.baseUri("URL2");
    requestSpec.headers("Authorization",token);
    Response res = requestSpec.get();
    
    Assert.assertTrue(res.statusCode()==200);
    res.prettyPrint();
    
    System.out.println("------------------- 2nd  TC is working---------------------");
    
    }

When I'm passing the headers in the first API call, the same header is getting passed again in the second API call. I want to remove all the headers which I passed in the first API call because I don't need those headers in the second API call.

The second API call requires no headers and in the authorization I'm passing jwt token which I got after the first API call, but it keeps passing the first API headers in the second API call.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

0 Answers0