Lot's of folks (myself included) have been asking
about the "basic authentication" for kSOAP. I
couldn't find a definite answer myself.. So here's
what I did:
- get the kSOAP source (downloadable from this
website)
- inside the HttpTransport class, you will find the
"call" method.
- i overrode (modified really) this method to take 2
more parameters ("Authorization", <auth credentials>)
- you will use the "connection.setRequestMethod()" in
the "call method" to set your authentication headers
- you will need the base64 class from kobjects to
encode your username and password for basic
authentication. (see this code below - thanks to John
Munch for the below code in this original post -->
http://ksoap.enhydra.org/project/mailingLists/ksoap/msg00278.html
) :
It depends on org.kobjects.base64.Base64
public String username = null;
public String password = null;
if (username != null && password != null)
{
StringBuffer buf = new
StringBuffer(username);
buf.append(':').append(password);
byte[] raw = buf.toString().getBytes();
buf.setLength(0);
buf.append("Basic ");
org.kobjects.base64.Base64.encode(raw, 0,
raw.length, buf);
connection.setRequestProperty
("Authorization",
buf.toString());
}
- So, What I did was use this code and the base64
class to encode my userID and password in my main
class. Instead of issuing the
"connection.setRequestProperty" above, I simply called
the my overridden ".call" method from HttpTransport
and passed it "Authorization",
buf.toString() - this call added this authorization
header to the kSOAP call and thus solved my basic
authentication problem...
Hope this helps!
stonedMonk.
RE: ------------
>Anyone have the patch to enable 'Basic
Authentication'?
>Thank you inadvance, Jason
__________________________________
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html
|