Results 1 to 3 of 3
Thread: PHP-
Hybrid View
-
21st July 2010 16:12 #1
PHP-
Java- , HTTP PHP- .
PHP, ?Code:/** * Writes user preferences. */ private void writePreferences(Properties properties) throws IOException { HttpURLConnection connection = null; try { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); properties.storeToXML(bytes, "Applet user preferences 1.0"); bytes.close(); connection = (HttpURLConnection)this.writePreferencesURL.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); connection.setDoOutput(true); connection.setDoInput(true); connection.setUseCaches(false); OutputStream out = connection.getOutputStream(); out.write("preferences=".getBytes("UTF-8")); out.write(URLEncoder.encode(new String(bytes.toByteArray(), "UTF-8"), "UTF-8").getBytes("UTF-8")); out.close(); // Read response InputStream in = connection.getInputStream(); int read = in.read(); in.close(); if (read != '1') { throw new IOException("Saving preferences failed"); } } finally { if (connection != null) { connection.disconnect(); } } }MSI B450 Gaming Pro Carbon AC | Ryzen 9 5900x | HyperX Predator 3200 | Asus Strix 3090 | Kingston KC3000 2TB | WD Red 4TB | Dell G3223Q + LG 27UK650-W | Arctic Freezer 360 | Seasonic Focus GX-1000 | Lian Li O11 Dynamic
-
21st July 2010 16:23 #2
$rawpostdata = trim(file_get_contents("php://input"));
file_put_contents('filename.txt', $rawpostdata);
echo '1';
exit;

URLEncoder , urldecode() .Last edited by tedych; 21st July 2010 at 16:30.
-
21st July 2010 16:41 #3
! , PHP. URLEncoder , . URL, . . , :
Code:/** * Reads user preferences. */ private void readPreferences(Properties properties) { URLConnection connection = null; InputStream in = null; try { // Open an input stream to server connection = this.readPreferencesURL.openConnection(); connection.setRequestProperty("Content-Type", "charset=UTF-8"); connection.setUseCaches(false); in = connection.getInputStream(); properties.loadFromXML(in); in.close(); } catch (IOException ex) { // Let default preferences unchanged } finally { try { if (in != null) { in.close(); } } catch (IOException ex) { // Let default preferences unchanged } } }MSI B450 Gaming Pro Carbon AC | Ryzen 9 5900x | HyperX Predator 3200 | Asus Strix 3090 | Kingston KC3000 2TB | WD Red 4TB | Dell G3223Q + LG 27UK650-W | Arctic Freezer 360 | Seasonic Focus GX-1000 | Lian Li O11 Dynamic




Reply With Quote
Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in