I am using below code to authenticate on server.
DefaultHttpClient Client = new DefaultHttpClient();
Client.getCredentialsProvider().setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials("username", "password"));
HttpGet get = new HttpGet(Url);
HttpResponse response = Client.execute(put);
If I use get it will work fine for me.
but when I use HttpPut it's not working .
DefaultHttpClient Client = new DefaultHttpClient();
Client.getCredentialsProvider().setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials("username", "password"));
HttpPut put = new HttpPut(Url);
HttpResponse response = Client.execute(put);
I need to upload file on server, so need to use HttpPut for this.
This will through 401 (authentication) error.
Can anybody have idew, why did I face this issue?
Thanks, Embedded Team
You can authenticate through
httpGET
and than upload file usinghttpPUT
, make sure you savecookies
.Why
httpPut
doesn't work? maybe its server side requirement to authenticate usingGET
. But surely it's a bad idea to useGET
request forauth
.