Java - sending HTTP parameters via POST method easily

前端 未结 17 1792
借酒劲吻你
借酒劲吻你 2020-11-21 05:54

I am successfully using this code to send HTTP requests with some parameters via GET method

void sendRequest(String request)
{
            


        
17条回答
  •  时光取名叫无心
    2020-11-21 06:58

    import java.net.*;
    
    public class Demo{
    
      public static void main(){
    
           String data = "data=Hello+World!";
           URL url = new URL("http://localhost:8084/WebListenerServer/webListener");
           HttpURLConnection con = (HttpURLConnection) url.openConnection();
           con.setRequestMethod("POST");
           con.setDoOutput(true);
           con.getOutputStream().write(data.getBytes("UTF-8"));
           con.getInputStream();
    
        }
    
    }
    

提交回复
热议问题