Java HTTP Request makeUrlRequest(String surl, String data, String method)

Here you can find the source of makeUrlRequest(String surl, String data, String method)

Description

make Url Request

License

Open Source License

Declaration

public static String makeUrlRequest(String surl, String data, String method) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class Main {
    public static String makeUrlRequest(String surl, String data, String method) throws IOException {
        URL url = new URL(surl);
        HttpURLConnection con;//w ww .  j  a  v  a2s .  co m
        con = (HttpURLConnection) url.openConnection();
        con.setRequestMethod(method);
        con.setRequestProperty("User-Agent", "EBA Client");
        con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
        con.setDoOutput(true);
        DataOutputStream wr = new DataOutputStream(con.getOutputStream());
        wr.writeBytes(data);
        wr.flush();
        wr.close();

        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String inputLine;
        StringBuffer response = new StringBuffer();

        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();
        return response.toString();
    }
}

Related

  1. getDataFromRequestViaPost(String request, String urlParameters)
  2. getOutputFromUrlConnection(String stringUrl, String requestProperty)
  3. getRequest(String urlString)
  4. getRequest(URL url, int timeout)
  5. getRequestContent(String urlText)
  6. request(boolean quiet, String method, URL url, Map body)
  7. request(String httpUrl, Map httpArgMap)
  8. request(String url, int timeout, String method, Map header)
  9. request(String url, Map cookies, Map parameters)