简体   繁体   中英

Setting headers in POST request with Java

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

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,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM