Authentication Error when using HttpPost with DefaultHttpClient on Android

后端 未结 4 1447
余生分开走
余生分开走 2020-12-16 16:20

I\'m running into a strange problem using HttpClient. I am using a DefaultHttpClient() with HttpPost. I was using HttpGet with 100% success but now trying to switch to HttpP

4条回答
  •  醉酒成梦
    2020-12-16 16:58

    Don't you have to declare the port and protocol? I'm just swagging this code so please don't be upset if it doesn't immediatley compile correctly. Also, I usually supply a UsernamePasswordCredentials to my setCredentials() but I imagine it's the same.

    HttpHost host = new HttpHost("www.foo.com", 443, "https");
    
    // assemble your GET or POST
    
    client.getCredentialsProvider().setCredentials(new AuthScope(host.getHostName(), host.getPort()));
    
    HttpResponse response = client.execute(host, [HttpPost or HttpGet]);
    

    More info about setCredentials here.

提交回复
热议问题