http 重定向 java,Java Http POST具有基本授权和重定向功能

The program does a http post with basic authorization just fine but when the post is complete the page is redirected to a success page. The redirect failes due to 401 authorization failed.

final URLConnection conn = url.openConnection();

conn.setDoOutput(true);

conn.setRequestProperty("Authorization", "basic " +base64);

wr = new OutputStreamWriter(conn.getOutputStream());

wr.write(data);

wr.flush();

rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));

The line

rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));

fails due to 401 authorization failed...

I have also tried adding

conn.setRequestProperty("Authorization", "basic " +base64);

after

wr.flush();

I get the error of "Already connected". Evidently the authorization that I set doesn't follow over to the redirect. Any solutions to this problem is greatly appreciated.

解决方案

You have 2 options you can try:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值