Setting headers in POST request with Java

2019-07-06 23:00发布

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

标签: java http post
1条回答
倾城 Initia
2楼-- · 2019-07-06 23:22

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,

查看更多
登录 后发表回答