Advertisement
Guest User

Untitled

a guest
Apr 14th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. FileInputStream fileStream = new FileInputStream(file);
  2. b = new byte[(int)file.length()];
  3. fileStream.read(b);
  4. fileName = file.getName();
  5. String crlf = "rn";
  6. String twoHyphens = "--";
  7. String boundary = "*****";
  8.  
  9. URL url = new URL(URL);
  10. connection = (HttpURLConnection)url.openConnection();
  11. connection.setDoOutput(true);
  12. connection.setDoInput(true);
  13. connection.setRequestMethod("POST");
  14. connection.setUseCaches( false );
  15. connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
  16.  
  17. DataOutputStream wr = new DataOutputStream( connection.getOutputStream());
  18. wr.writeBytes(twoHyphens+boundary+crlf);
  19. wr.writeBytes("Content-Disposition: form-data; process="extractText";user="" + username + "";pass="" + password + "";filename="" + file.getName() + "";file="");
  20. wr.write(b);
  21. wr.writeBytes(""" + crlf);
  22. wr.writeBytes(crlf);
  23. wr.writeBytes(twoHyphens + boundary + twoHyphens + crlf);
  24. wr.flush();
  25. wr.close();
  26.  
  27. responseStream = new InputStreamReader(connection.getInputStream());
  28. BufferedReader br = new BufferedReader(responseStream);
  29. strBuff = new StringBuffer();
  30. String s;
  31. while ( ( s = br.readLine() ) != null ) {
  32. strBuff.append(s);
  33. }
  34. br.close();
  35. responseStream.close();
  36. connection.disconnect();
  37. str = strBuff.toString();
  38. data = str;
  39. parser = new JSONParser();
  40. jsonObj = (JSONObject)parser.parse(str);
  41. str = jsonObj.get("status").toString();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement