开发者

How to get parameter Request from http header in java

i want to create a proxy ,the method GET work fine ,but POST no ,cause i can't get the parameter from the header http to send it to the server :

example of what i get:

POST http://site/index.php HTTP/1.1
Host: host
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8开发者_如何学C
Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Proxy-Connection: keep-alive
Referer: http://site/index.php
Content-Type: application/x-www-form-urlencoded
Content-Length: 112

after that i should have the parameters:

Login=toto&Password=motdepasse&submit=envoyer

but i cant see it on the trace

the code that i use to get th trace is :

BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

    while((inputLine = in.readLine()) != null){
            try{

               ligne+=inputLine+"\n";
               StringTokenizer tok = new StringTokenizer(inputLine);
               tok.nextToken();


           }catch(Exception e){
               break;
             //   System.out.println("ERROR :" + e.getMessage());

           }
        }



      public static String excutePost(String targetURL, String urlParameters)
  {  
  //Create connection
  URL url = new URL(targetURL);
  HttpURLConnection connection = (HttpURLConnection)url.openConnection();
  connection.setRequestMethod("POST");
  connection.setRequestProperty("Content-Type","application/x-www-form-  urlencoded");          
  connection.setUseCaches (false);
  connection.setDoInput(true);
  connection.setDoOutput(true);
  //Send request
  DataOutputStream wr = new DataOutputStream (
  connection.getOutputStream ());
   wr.writeBytes (urlParameters);
   wr.flush ();
   wr.close ();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜