简体   繁体   English

java linux中的http包导入错误

[英]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. 嗨,我使用Linux,当我尝试导入以下软件包时,编译出错。

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. 我如何在Linux中安装这些软件包,然后进行编译。 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 javac -cp。; httpclient.jar MyClass.java

java -cp .;httpclient.jar MyClass java -cp。; httpclient.jar MyClass

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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