简体   繁体   中英

import error for http package in java linux

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);
    }
} 

Try

javac -cp .;httpclient.jar MyClass.java

java -cp .;httpclient.jar MyClass

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM