Send API request manually

I’m trying to send request manually, but I don’t want to create Web Service Request in Object Repository.

JsonSlurper slurper = new JsonSlurper()
String endpoint = GlobalVariable.url
RequestObject request = ?
request.setRestUrl(endpoint)
ResponseObject response = WS.sendRequestAndVerify(request)
String getcontent = response.getResponseBodyContent()

println getcontent

with RequestObject request = findTestObject(‘Object Repository/API’) works but I want to write without creating and adding “findTestObject”

Is it possible to make that ?

? = new RequestObject() :slight_smile:

When I type that, it gives me an error: Unable to parse HTTP request

Can you post whole exception you got?

image

It looks like this is the response which API returns to you. Probably you missed something in the request (auth header? content type? cookie?)

1 Like

I was not adding headers, but it should work without headers no ? When I’ve created web service request, I have not added headers by myself.

I don’t know, it’s your API. :slight_smile: Maybe try to get status code from your response and ask your developer what you miss in the request.

in endpoint I’ve wrote google.com and output is the same.

I think I know what happens here. You use sendRequestAndVerify method, but you don’t specify a verification script (as you may have in TestObject from Object repository). So try to use just sendRequest method.

You were right ! The problem was just in the headers, but also I did not had Array for the headers. I was just giving setting i.e header1 and header2 insted of “defaultHeaders”