java – 使用HTTP基本验证与Google App Engine URLFetch服务

如何指定用于使用App Engine的URLFetch服务(在Java中)进行Basic-Auth请求的用户名和密码?

看来我可以设置HTTP标头:

URL url = new URL("http://www.example.com/comment");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("X-MyApp-Version", "2.7.3");        

适用于Basic-Auth的头文件是什么?

这是一个基本的auth头通过http:

授权:基本base64编码(用户名:密码)

例如:

GET /private/index.html HTTP/1.0
Host: myhost.com
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==

您将需要这样做:

URL url = new URL("http://www.example.com/comment");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Authorization",
"Basic "+codec.encodeBase64String(("username:password").getBytes());

要做到这一点,你会想要得到一个base64编解码器api,就像Apache Commons Codec

http://stackoverflow.com/questions/1341081/using-http-basic-auth-with-google-app-engine-urlfetch-service

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:java – 使用HTTP基本验证与Google App Engine URLFetch服务