且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用HTTP标头发送HTTP请求

更新时间:2022-04-12 22:16:07

尤尔code是罚款。你有HTTP客户端安装正确,并添加正确的标题。但。你的基本身份验证是错误的。标题密钥(认证)是正确的,但该值应该是基本+ Base64.en code(用户名+:+通)

Yor code is fine. you have the http client setup right and the header added right. but. your basic authentication is wrong. the header key (Authentication) is right but the value should be Basic + Base64.encode(username+":"+pass)

也替代是如下因素code:

also the alternative to that is the folowing code:

 httpclient.getCredentialsProvider().setCredentials(
                new AuthScope(targetHost.getHostName(), targetHost.getPort()),
                new UsernamePasswordCredentials("username", "password"));

目标主机名可能是零和端口-1。

The target Hostname is probably null and the port -1.

不过这一次,你将无法如果您使用的URL连接,所以一个头也是可以接受的使用。

but this one you wont be able to use if you are using url connection so a header is also acceptable.

编辑:

这是您的问题:

String auth = android.util.Base64.encodeToString(
    ("florin999@zitec.ro" + ":" + "test2323" + ":" + "zitec"
    + ":" + "7716099f468cc71670b68cf4b3ba545c5760baa7")
    .getBytes("UTF-8"), android.util.Base64.NO_WRAP);

什么是所有theese串联??

What are all theese concatenations??

基本身份验证是指将一个base64连接codeD Authorization头该字的consisnt 基本+ Base64.en codeToString(yourUsername+:+你的密码)

Basic authentication means adding a base64 encoded Authorization header which consisnt of the word "Basic " + Base64.encodeToString("yourUsername"+":"+"yourPassword)

另一种方法是添加方法i贴在有关凭据提供顶部同样的方式

The alternative is adding the method i pasted at the top about the credentials provider the same way