本文介绍了在Google App Engine URLFetch服务中使用HTTP Basic-Auth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用App Engine的服务(在Java中)?
看来我可以设置HTTP标头:
网址url =新网址(http://www.example.com/comment);
HttpURLConnection连接=(HttpURLConnection)url.openConnection();
connection.setRequestProperty(X-MyApp-Version,2.7.3);
Basic-Auth的标题是什么?
解决方案
这是一个基于http的基本认证头:授权:基本base64编码(用户名:密码)
p>例如:
GET /private/index.html HTTP / 1.0
主机:myhost.com
授权:基本QWxhZGRpbjpvcGVuIHNlc2FtZQ ==
您需要要做到这一点:
URL url = new URL(http://www.example.com/comment);
pre>
HttpURLConnection连接=(HttpURLConnection)url.openConnection();
connection.setRequestProperty(Authorization,
Basic+ codec.encodeBase64String((username:password)。getBytes());
要做到这一点,您需要获得一个base64编解码器API,如
How can I specify the username and password for making Basic-Auth requests with App Engine's URLFetch service (in Java)?
It seems I can set HTTP headers:
URL url = new URL("http://www.example.com/comment"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("X-MyApp-Version", "2.7.3");
What are the appropriate headers for Basic-Auth?
解决方案This is a basic auth header over http:
Authorization: Basic base64 encoded(username:password)
eg:
GET /private/index.html HTTP/1.0 Host: myhost.com Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
You will need to do this:
URL url = new URL("http://www.example.com/comment"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Authorization", "Basic "+codec.encodeBase64String(("username:password").getBytes());
And to do that you will want to get a base64 codec api, like the Apache Commons Codec
这篇关于在Google App Engine URLFetch服务中使用HTTP Basic-Auth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!