• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps PUT with Basic Auth

mellis

Lurker
Hello all:

We are porting our app from WM6.5 to Android. The app talks to our servers (Win Server 2003 IIS6 and 2008 II7) with PUTs and GETs.

WM6.5 works fine on all platforms.
Android can GET files on all platforms and send files to Win Server 2003.

Problem is when I am trying to send files to Win Server 2008. The server is giving me an IO Exception "No authentication challenges found". We are using Basic Auth since this is not a public app but closed loop. I have included the send file code for your review. I have been scouring the web and seen many posts RE this subject but to the best of my recollection this should work (since it already does on Win Server 2003???):

[HIGH]

//CREATE URL
u =​
new URL(url + filename);
conn = (HttpURLConnection)u.openConnection();​
//AUTH INFO
auth =​
"Basic " + Base64.encodeToString("user:passwd".getBytes(), Base64.NO_WRAP);

conn.setRequestProperty(​
"Authorization", auth);

//METHOD (PUT A FILE)
conn.setRequestMethod(​
"PUT");

//CONNECTION TIMEOUT
conn.setConnectTimeout(5000);​
//CONNECT
conn.connect();​
//WRITE THE FILE STUFF
out = conn.getOutputStream();​
out.write(stuff);​
out.close();​
//GET RESPONSES
temp = conn.getResponseMessage();​
code = conn.getResponseCode();​
if (code != 200 && code != 201){
conn.disconnect();​
return"!ERROR:" + temp;
[/HIGH]​

Thanks in advance!

Marshall
 
Back
Top Bottom