Results 1 to 3 of 3

Thread: PHP-

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    1+1=11 svr's Avatar
    Join Date: Sep:2006
    Location: Inferno, Act 1
    Posts: 790

    PHP-

    Java- , HTTP 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();
          }
        }
      }
    PHP, ?
    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

  2. #2
    Registered User tedych's Avatar
    Join Date: Nov:2003
    Location:
    Posts: 17,654
    $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.

  3. #3
    1+1=11 svr's Avatar
    Join Date: Sep:2006
    Location: Inferno, Act 1
    Posts: 790
    ! , 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |