cURL with --data-binary trying to automate with rest-assured throws 500 error

241 views
Skip to first unread message

80Vikram

unread,
Oct 23, 2018, 8:56:39 AM10/23/18
to REST assured
Hi All,

I've cURL as below

curl -H 'Host: api.staging.test.com' -H 'accept: application/json' -H 'content-type: application/json; charset=utf-8' -H 'user-agent: okhttp/3.10.0' --data-binary '{"emailId":"te...@test.com","password":"test123"}' --compressed 'https://api.staging.test.com/user/develop-account/v1/session?storeId=100'

I'm trying to automate this with rest-assured as below

request = given().
                        log().all().
                                auth().basic("te...@test.com", "test123").
                                header("Host", HOST_HEADER).
                                header("user-agent", USER_AGENT).
                                header("accept", ACCEPT).
                                header("content-type", CONTENT_TYPE);

response = request.when().

  json = response.then().statusCode(200);


But getting 500, log-in works fine without rest-assured though. I'm not getting where am I going wrong

Thanks,
Vikram

Johan Haleby

unread,
Oct 24, 2018, 5:58:31 AM10/24/18
to rest-a...@googlegroups.com
Hmm maybe you could try preemptive basic authentication? Also I don't see that you provide any body with rest assured?

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

80Vikram

unread,
Oct 24, 2018, 6:43:48 AM10/24/18
to REST assured
Hi Johan,

I tried as below with preemptive auth but still getting 500

? Is there a way to get more info from API why is it throwing error 

? Can you please clarify why body needs to be provided with rest assured in this case 

Thanks in advance

        request = given().
log().all().
auth().preemptive().basic("te...@test.com", "test123").

header("Host", HOST_HEADER).
header("user-agent", USER_AGENT).
header("accept", ACCEPT).
header("content-type", CONTENT_TYPE);

        response = request.when().
post(ENDPOINT_FOR_LOGIN);

        response.then().statusCode(200);


Regards,
Vikram

80Vikram

unread,
Oct 24, 2018, 7:21:56 AM10/24/18
to REST assured
Hi Johan,

Thanks for your pointer, I could solve the issue as below


Map<String, Object> params = new HashMap<>();
params.put("emailId", "te...@test.com");
params.put("password", "test123");

request = given().
log().all().

header("Host", HOST_HEADER).
header("user-agent", USER_AGENT).
header("accept", ACCEPT).
                        header("content-type", CONTENT_TYPE).
contentType(JSON).
body(params);

response = request.when().
post(ENDPOINT_FOR_LOGIN);


json = response.then().statusCode(200);



import static io.restassured.http.ContentType.JSON;

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
<scope>test</scope>
</dependency>

Regards,
Vikram


On Wednesday, October 24, 2018 at 12:43:48 PM UTC+2, 80Vikram wrote:
Hi Johan,

I tried as below with preemptive auth but still getting 500

? Is there a way to get more info from API why is it throwing error 

? Can you please clarify why body needs to be provided with rest assured in this case 

Thanks in advance

        request = given().
log().all().
auth().preemptive().basic("test...@test.com", "test123").
Reply all
Reply to author
Forward
0 new messages