Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting headers in POST request with Java

Tags:

java

http

post

I use Robotium to test Android app. In the middle of a test I need to create POST request to server to some money to user and then verify that changes are reflected in UI.

Request looks like:

wwww.testserver.com/userAddMoney?user_id=1&amount=999

But to authorize on server I need to pass special parameters to Header of request:

Headers: X-Testing-Auth-Secret: kI7wGju76kjhJHGklk76

like image 722
z3us Avatar asked Jan 18 '26 12:01

z3us


1 Answers

You could look into the Apache HC package:

HttpPost post = new HttpPost( "http://wwww.testserver.com/userAddMoney" );
...
post.addHeader( "X-Testing-Auth-Secret" , "kI7wGju76kjhJHGklk76" );
...

Cheers,

like image 126
Anders R. Bystrup Avatar answered Jan 21 '26 02:01

Anders R. Bystrup



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!