~simernes/+junk/dhis-android-reporting

« back to all changes in this revision

Viewing changes to src/no/uio/inf5750/assignment3/util/ConnectionManager.java

  • Committer: Simen
  • Date: 2013-09-16 15:28:20 UTC
  • Revision ID: simen_russnes@hotmail.com-20130916152820-sro6sftnu36j6mns
writeing message working

Show diffs side-by-side

added added

removed removed

Lines of Context:
131
131
                String usersXML = "";
132
132
                for(int i = 0; i<users.size(); i++)
133
133
                {
134
 
                        usersXML = "<user id=\"" + users.get(i).mId+"\" />";
 
134
                        usersXML += "<user id=\"" + users.get(i).mId+"\" />";
135
135
                }
136
136
                xml += usersXML + "</users>";
137
137
                xml += "</message>";
138
138
                System.out.println(xml);
139
139
                
140
 
                doPost(Message.getConversationBaseUrl(), xml);
 
140
                doPost(Message.getConversationBaseUrl(), xml, "application/xml");
141
141
        }
142
142
        
143
143
        /**
265
265
                
266
266
        }
267
267
        
 
268
        /**
 
269
         * Executes a HTTP post with a given content
 
270
         * @param url POST URL
 
271
         * @param contentType the content type of the request
 
272
         * @param content The content to be sent in the post
 
273
         */
 
274
        public void doPost(String url, String content, String contentType) {
 
275
                HttpPost httppost = new HttpPost(url);
 
276
                httppost.setHeader("Content-Type", contentType);
 
277
                httppost.setHeader("Authorization", "Basic " + getEncodedUserInfo());
 
278
                
 
279
                try {
 
280
                        httppost.setEntity(new StringEntity(content));
 
281
                } catch (UnsupportedEncodingException e) {
 
282
                        // TODO Auto-generated catch block
 
283
                        e.printStackTrace();
 
284
                        return;
 
285
                }
 
286
                HttpClient httpclient = new DefaultHttpClient();
 
287
                
 
288
                
 
289
                HttpResponse response = null;
 
290
                try {
 
291
                        response = httpclient.execute(httppost);
 
292
                } catch (ClientProtocolException e) {
 
293
                        // TODO Auto-generated catch block
 
294
                        e.printStackTrace();
 
295
                } catch (IOException e) {
 
296
                        // TODO Auto-generated catch block
 
297
                        e.printStackTrace();
 
298
                }
 
299
                
 
300
                System.out.println("url: " + url);
 
301
                
 
302
        }
 
303
        
268
304
        public void setAccount(int position, Context context)
269
305
        {
270
306