android, how to send username and password to webservice as header fields? -


i trying create application on android phone takes username , password user, encrypt password using md5 connect url these parameters.

a code connect worked fine on iphone, couldn't find in android:

nsmutableurlrequest* request = [nsmutableurlrequest requestwithurl:myurl];  [request sethttpmethod:@"get"];  [request addvalue:usernamefield.text forhttpheaderfield:@"username"];  [request addvalue:md5pass2 forhttpheaderfield:@"password"]; 

i tried connect via httpurlconnection used post/get dataoutputstream, httpclient send parameters httpget/httppost, no success.

i think need send parameters headerfield don't know how.

note: compared encryption results , correct.

i find apache library more straightforward when comes http.

an example of follows:

defaulthttpclient client = new defaulthttpclient(); httpget request = new httpget(); request.seturi(new uri("http://www.internet.com/api")); 

normally request use parameters, ie append them end of url so:

string url = "http://www.internet.com/api?username=yourusername&password=yourpassword"  request.seturi(new uri(url)); 

but since specified want them headers could:

request.addheader("username", username); request.addheader("password", password); 

and then:

httpresponse response = client.execute(request); //parse response input stream object inside httpresponse 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -