Android : Tell me how to send the Json request

on Wednesday, January 28, 2015


I am sending the json request code give the error Is there any way how to send the json request with authentication



//st = json object




OAuthConsumer consumer = new DefaultOAuthConsumer("tOzL5hTkSz9KiA2RIAECFL","cj8HLIvzntPmAsffLe5q");
consumer.setTokenWithSecret(null, null); //i pass token as access token as a null as my server dont need it.

URL url = new URL("http://api.seatseller.travel/blockTicket");
HttpURLConnection request = (HttpURLConnection) url.openConnection();

consumer.sign(request);
request.connect();

// send the request
JSONObject jsonParam = st;
OutputStreamWriter printout = new OutputStreamWriter(request.getOutputStream());
printout.write(st.toString());//writeUTF(URLEncoder.encode(jsonParam.toString(),"UTF-8"));
printout.flush ();
printout.close ();

InputStream in = new BufferedInputStream(request.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder out1 = new StringBuilder();
String line = "";
while ((line = reader.readLine()) != null)
{
out1.append(line);
}
String result= out1.toString() ;

0 comments:

Post a Comment