使用Java在POST请求中设置标头 [英] Setting headers in POST request with Java

查看:1398
本文介绍了使用Java在POST请求中设置标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Robotium测试Android应用.在测试的中间,我需要向服务器创建POST请求以向用户支付一些钱,然后验证更改是否反映在UI中.

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.

请求看起来像:

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

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

但是要在服务器上进行授权,我需要将特殊参数传递给请求的标头:

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

标题:X-Testing-Auth-Secret:kI7wGju76kjhJHGklk76

Headers: X-Testing-Auth-Secret: kI7wGju76kjhJHGklk76

推荐答案

您可以查看 Apache HC 软件包:

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

干杯

这篇关于使用Java在POST请求中设置标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆