Java call thirdparty url with parameters in POST from a servlet -


from java web application, want call third party site url. third party url needs input parameters accept via post.and these inputs not customer using site. , third party page displayed in iframe of site. able jsp file have inputs hidden , have onload form submit below:

<body onload="document.form1.submit()">     <%           response.setheader("cache-control","no-cache"); //http 1.1         response.setheader("pragma","no-cache"); //http 1.0         response.setdateheader ("expires", 0);     %>   <form method="post" action="<%= (string)request.getattribute("thridpartyurl") %>" id=form1 name=form1> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="rightbox">      <tr>         <td>         <input type="hidden" name="param1" value="<%= (string)request.getattribute("param1") %>">                 <input type="hidden" name="param2" value="<%= (string)request.getattribute("param2") %>">          </td>     </tr> </table>     </form> </body> 

but want avoid jsp submission. looking way without involvement of jsp. there way in java. little search, understand response.sendredirect cannot post submission. , dispatcher.forward(request, response) cannot use outside project urls.

please help.

regards,

below java code call http url.

    string url = "thirdparty site url";      url obj = new url(url);      httpsurlconnection con = (httpsurlconnection) obj.openconnection();      //add reuqest header     con.setrequestmethod("post");       string urlparameters = "param1=value1&param2=value2";      // send post request     con.setdooutput(true);     dataoutputstream wr = new dataoutputstream(con.getoutputstream());     wr.writebytes(urlparameters);     wr.flush();     wr.close();      int responsecode = con.getresponsecode();     system.out.println("\nsending 'post' request url : " + url);     system.out.println("post parameters : " + urlparameters);     system.out.println("response code : " + responsecode);      bufferedreader in = new bufferedreader(             new inputstreamreader(con.getinputstream()));     string inputline;     stringbuffer response = new stringbuffer();      while ((inputline = in.readline()) != null) {         response.append(inputline);     }     in.close();      //print result     system.out.println(response.tostring()); 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -