I want to make an HTTP POST format as follows:
<?xml version="1.0" encoding="UTF-8" ?> <authRequest> <username>someusernamehere</username> <password>somepasswordhere</password> </authRequest>
I usually work with the following mechanism for any input based POST,
HttpParams params = new BasicHttpParams(); params.setParameter( "http.useragent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6"); DefaultHttpClient httpclient = new DefaultHttpClient(params); HttpPost httppost = new HttpPost("http://mysite.com/login"); List<NameValuePair> formparams = new ArrayList<NameValuePair>(); formparams.add(new BasicNameValuePair("username", "stackoverflow")); formparams.add(new BasicNameValuePair("password", "12345")); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8"); httppost.setEntity(entity); HttpResponse httpresponse = httpclient.execute(httppost);
But in this way, the POST data will look,
username=stackoverflow&password=12345
How can I format this request in accordance with the above XML format?
Thanks in advance.
source share