0

Hi i use linux and when i try to import the following packages compilation is giving error.

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;

import com.google.gson.Gson;

How can i install these packages in my linux and then compile. My code as follows,

class pojo1
{
  String name=abc;
  String age=18;
  //generate setter and getters
}

public class SimpleURL
{
public static void main(String[] args)
    {
    String postUrl="www.site.com";// put in your url
    Gson gson= new Gson();
    HttpPost post = new HttpPost(postUrl);
    StringEntity  postingString = new StringEntity(gson.toJson(pojo1));//convert your pojo to   json
    post.setEntity(postingString);
    post.setHeader("Content-type","application/json");
    HttpResponse  response = httpClient.execute(post);
    }
} 
Naggappan Ramukannan
  • 2,564
  • 9
  • 36
  • 59

1 Answers1

0

Try

javac -cp .;httpclient.jar MyClass.java

java -cp .;httpclient.jar MyClass

Karthigeyan Vellasamy
  • 2,038
  • 6
  • 33
  • 50