I m including the server code for GET request. Post and delete follow the same pattern:
while(true){ socket = serverSocket.accept(); conn = new DefaultHttpServerConnection(); conn.bind(socket,new BasicHttpParams()); HttpRequest request; try { request = conn.receiveRequestHeader(); String target = request.getRequestLine().getUri(); target = target.replaceAll("/",""); String method = request.getRequestLine().getMethod(); Code for handling GET request: ------------------------------ if(method.equals("GET")) { if(checkFileExisting()) { BufferedReader reader = new BufferedReader(new FileReader(new File(getFilesDir()+File.separator+"script.json"))); String read; StringBuilder builder = new StringBuilder(""); while((read = reader.readLine()) != null) { builder.append(read); } String JSONContents = builder.toString(); reader.close(); JSONObject jsonObject; try { jsonObject = new JSONObject(JSONContents); String name = jsonObject.getString("name"); JSONObject stateObject = jsonObject.getJSONObject("state"); String stateValue = stateObject.getString("value"); if(name.equals(target)) { HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK"); response.setEntity(new StringEntity("State is:" + stateValue)); conn.sendResponseHeader(response); conn.sendResponseEntity(response); } else { HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 404, "Not Found"); response.setEntity(new StringEntity("The requested resource " + target + " could not be found due to mismatch!!")); conn.sendResponseHeader(response); conn.sendResponseEntity(response); } } catch (JSONException e) { e.printStackTrace(); } } else { HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 404, "Not Found"); response.setEntity(new StringEntity("The requested resource " + target + " could not be found!!")); conn.sendResponseHeader(response); conn.sendResponseEntity(response); } } Thanks! On Thursday, December 13, 2012 10:10:13 AM UTC+2, skink wrote: > > > > Archana wrote: > > I m getting a Timeout or No Response from server in Mozilla Poster(when > I > > issue GET and DELETE requests), while able to see the response from the > > server in the logs. So I thought, this is due to blocking of > > sockets/ports(as I am utilizing only one in my case). > > > > > and your server's code is? > > pskink > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en