Results 1 to 3 of 3
  1. #1
    Tores is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default Send post form data into external url

    Hello and happy programming with Java

    I need to convert this php code into jsp code. The code test if there is a post request and if there is the code grab posted parameters from the post sequence and make a query string of posted variables, than pass this string to an external script to be fetched and return the value received.
    Especially I don't know how to do the following :

    1 - Test if there is a post request
    2 - Build a query string of all posted data
    3 - An equivalent to file_get_contents in Java

    Below is the entire php code I want to convert to Java :

    PHP Code:
    $query_string = "";
    if($_SERVER['REQUEST_METHOD'] == 'POST'){
    $kv=array();
    foreach($_POST as $key=>$value){
    $kv[]="$key=$value";
    }
    $query_string = join("&",$kv);
    $url = "http://externalwebsite.com/script.php?" . $query_string;
    $content = file_get_contents($url);
    }else{
    $query_string = $_SERVER['QUERY_STRING'];
    }
    
    ?>
    Regards

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Send post form data into external url

    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Send post form data into external url

    For the POST vs GET then stick this in a servlet.
    It has doPost and doGet methods, so does that part for you.

Similar Threads

  1. proxy ip send post request
    By rojersjoo in forum Networking
    Replies: 4
    Last Post: 02-18-2012, 03:36 AM
  2. Send Data to External System
    By ksur12345 in forum New To Java
    Replies: 3
    Last Post: 07-28-2011, 05:06 PM
  3. Replies: 8
    Last Post: 10-03-2010, 10:45 AM
  4. Send a XML file by POST to a server in php
    By rui.pereira in forum New To Java
    Replies: 0
    Last Post: 04-06-2010, 11:46 AM
  5. enctype=multipart/form-data with form data in struts
    By vk_satheesh in forum New To Java
    Replies: 0
    Last Post: 09-19-2008, 01:48 PM

Posting Permissions

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