eclipse - Java - sending POST -
i'm trying make java make new addition url shortener, here's have:
private void sendpost() throws exception { string url = "http://shmkane.com/index.php?"; url obj = new url(url); httpurlconnection con = (httpurlconnection) obj.openconnection(); con.setrequestmethod("post"); con.setrequestproperty("user-agent", user_agent); con.setrequestproperty("accept-language", "en-us,en;q=0.5"); string urlparameters = "url=testingthis"; 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(); system.out.println(response.tostring()); }
i'd put in "form1" , "submit" here's site
i'm new great, possible tell me i'm doing wrong or improving/fixing code have.
that site doesn't support post:
<form method="get" id="form1" action="index.php"> <p> </p> <p><br> <input class="textbox" id="url" placeholder="paste link shorten it" type="text" name="url" value=""> </p> <p> <input class="textbox" placeholder="custom alias" id="alias" maxlength="15" type="text" name="alias" value=""> </p> <div class="button"> <p> <input class="button" type="submit" value="shorten"> </p> <br> <div class="alert-box success"> <center> <a href="" target="_blank"></a> </center> </div> <em>may contain letters, numbers, dashes , underscores.</em> <p></p> </div> </form>
notice method get
. change this:
string urlparameters = "url=testingthis"; string url = "http://shmkane.com/index.php?"; url obj = new url(url + urlparameters); httpurlconnection con = (httpurlconnection) obj.openconnection(); con.setrequestmethod("get");
and rid of writing output stream.
Comments
Post a Comment