Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FileInputStream fileStream = new FileInputStream(file);
- b = new byte[(int)file.length()];
- fileStream.read(b);
- fileName = file.getName();
- String crlf = "rn";
- String twoHyphens = "--";
- String boundary = "*****";
- URL url = new URL(URL);
- connection = (HttpURLConnection)url.openConnection();
- connection.setDoOutput(true);
- connection.setDoInput(true);
- connection.setRequestMethod("POST");
- connection.setUseCaches( false );
- connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
- DataOutputStream wr = new DataOutputStream( connection.getOutputStream());
- wr.writeBytes(twoHyphens+boundary+crlf);
- wr.writeBytes("Content-Disposition: form-data; process="extractText";user="" + username + "";pass="" + password + "";filename="" + file.getName() + "";file="");
- wr.write(b);
- wr.writeBytes(""" + crlf);
- wr.writeBytes(crlf);
- wr.writeBytes(twoHyphens + boundary + twoHyphens + crlf);
- wr.flush();
- wr.close();
- responseStream = new InputStreamReader(connection.getInputStream());
- BufferedReader br = new BufferedReader(responseStream);
- strBuff = new StringBuffer();
- String s;
- while ( ( s = br.readLine() ) != null ) {
- strBuff.append(s);
- }
- br.close();
- responseStream.close();
- connection.disconnect();
- str = strBuff.toString();
- data = str;
- parser = new JSONParser();
- jsonObj = (JSONObject)parser.parse(str);
- str = jsonObj.get("status").toString();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement