I am working on a user login page from android to C# .net service it accepts only XML and have to use HTTP POST method I am able to hit the server and get response using JSON but the USERNAME and LOGIN credentials alone coludnt be passed properly i get the response as
Input was not in Correct Format
could some one help me
i got the response from server using JSON code aas below:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"http://mydomain.com/api.svc/usr/?fmt=json");
httppost.addHeader("POINT_ID", "WEB02");
httppost.addHeader("AUTH_CODE", "JAbmQX5pbBpMTF0pMTbCg==");
List<NameValuePair> paarams = new ArrayList<NameValuePair>();
paarams.add(new BasicNameValuePair("Mode", "login"));
paarams.add(new BasicNameValuePair("LoginId", "api@api.in"));
paarams.add(new BasicNameValuePair("Password", "123456"));
try {
httppost.setEntity(new UrlEncodedFormEntity(paarams, "UTF-8"));
} catch (UnsupportedEncodingException e) {
// writing error to Log
e.printStackTrace();
}
/*
* Execute the HTTP Request
*/
try {
HttpResponse response = httpclient.execute(httppost);
HttpEntity respEntity = response.getEntity();
statCode = response.getStatusLine().getStatusCode();
if (respEntity != null) {
// EntityUtils to get the response content
content = EntityUtils.toString(respEntity);
}
} catch (ClientProtocolException e) {
// writing exception to log
e.printStackTrace();
} catch (IOException e) {
// writing exception to log
e.printStackTrace();
}
The xml looks like as below
<User>
<Mode>login</Mode>
<LoginId>api@api.in</LoginId>
<Password>123456</Password>
<Name>Guest</Name>
<SessionId>5</SessionId>
<Id>7</Id>
<Guest>Y</Guest>
<Country>USD</Country>
</User>
i was able to get till User but the login and password failed to hit properly
I was then said that api accepts only xml so i tried with below xml hardcoding the username , password in the xml itself
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"http://mydomain.com/api.svc/usr/?fmt=json");
httppost.addHeader("POINT_ID", "WEB02");
httppost.addHeader("AUTH_CODE", "JAbmQX5pbBpMTF0pMTbCg==");
try {
StringEntity se = new StringEntity( "<User><Mode>login</Mode><LoginId>api@api.in</LoginId><Password>123456</Password><Name>My API</Name><SessionId>5</SessionId><Id>7</Id><Guest>Y</Guest><Country>USD</Country></User>", HTTP.UTF_8);
se.setContentType("text/xml");
httppost.setEntity(se);
HttpResponse httpresponse = httpclient.execute(httppost);
HttpEntity resEntity = httpresponse.getEntity();
statCode = httpresponse.getStatusLine().getStatusCode();
content=EntityUtils.toString(resEntity);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
But for the above xml i get only the Request Error html page with HTML tags and CSS
I tried browsing so links like below
- http://developer.appcelerator.com/question/148810/send-xml-data-to-webservice
- how to post xml data to server in android
- Android, send and receive XML via HTTP POST method
- http://sunil-android.blogspot.in/2013/04/jquery-ajax-request-and-response.html
- Sending HTTP POST Request In Java
- Ajax post data in android java
but most of those links are passing the username password along with the api link but the api im trying uses post,beforesend and data so some one help me to authenticate user login for this api
THANKS IN ADVANCE