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

由网友(往事通缉犯)分享简介:在此先感谢... 使用此$ C $下的HTTP标头中的HTTP请求的URL进行身份验证IM。i m using this code for set http header in http request for authenticate url..但我觉得有些东西是mising这就是为什么我不能得到回应........

在此先感谢...

使用此$ C $下的HTTP标头中的HTTP请求的URL进行身份验证IM。

i m using this code for set http header in http request for authenticate url..

但我觉得有些东西是mising这就是为什么我不能得到回应......

but i think some what is mising thats why i could not get response...

响应仍然来自像需要authoriazation......

response still comes like "authoriazation required"...

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

HttpConnectionParams.setSoTimeout(httpParameters, 0);
client = new DefaultHttpClient(httpParameters);
String getURL = "URL here";
get = new HttpGet(getURL);
get.addHeader("Authorization", "Basic "+ auth);
// get.addHeader("X-ZFWS-Accept", "text/json");

HttpResponse responseGet = client.execute(get);
HttpEntity resEntityGet = responseGet.getEntity();
if (resEntityGet != null) {
    //do something with the response
    //Toast.makeText(Login.this.getApplicationContext(),EntityUtils.toString(resEntityGet), Toast.LENGTH_SHORT).show();
    String s = EntityUtils.toString(resEntityGet);
    tv1.setText(s);
}
}catch(Exception e){
}

plssss帮助我尽快

plssss help me as soon as possible

推荐答案

尤尔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

阅读全文

相关推荐

最新文章