首页编程namevaluepair(java里的“NameValuePair”是什么类型有什么用)

namevaluepair(java里的“NameValuePair”是什么类型有什么用)

编程之家2023-11-03109次浏览

你是否对于namevaluepair和java里的“NameValuePair”是什么类型有什么用感到困惑?别担心,今天小编将为您揭开这个谜团,让我们一同探索吧!

namevaluepair(java里的“NameValuePair”是什么类型有什么用)

java里的“NameValuePair”是什么类型有什么用

NameValuePair是简单名称值对节点类型。多用于Java像url发送Post请求。在发送post请求时用该list来存放参数。

Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。

Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程。

Java具有简单性、面向对象、分布式、健壮性、安全性、平台独立与可移植性、多线程、动态性等特点。Java可以编写桌面应用程序、Web应用程序、分布式系统和嵌入式系统应用程序等。

20世纪90年代,硬件领域出现了单片式计算机系统,这种价格低廉的系统一出现就立即引起了自动控制领域人员的注意,因为使用它可以大幅度提升消费类电子产品(如电视机顶盒、面包烤箱、移动电话等)的智能化程度。

Sun公司为了抢占市场先机,在1991年成立了一个称为Green的项目小组,帕特里克、詹姆斯·高斯林、麦克·舍林丹和其他几个工程师一起组成的工作小组在加利福尼亚州门洛帕克市沙丘路的一个小工作室里面研究开发新技术,专攻计算机在家电产品上的嵌入式应用。

namevaluepair(java里的“NameValuePair”是什么类型有什么用)

由于C++所具有的优势,该项目组的研究人员首先考虑采用C++来编写程序。但对于硬件资源极其匮乏的单片式系统来说,C++程序过于复杂和庞大。

另外由于消费电子产品所采用的嵌入式处理器芯片的种类繁杂,如何让编写的程序跨平台运行也是个难题。为了解决困难,他们首先着眼于语言的开发,假设了一种结构简单、符合嵌入式应用需要的硬件平台体系结构并为其制定了相应的规范,其中就定义了这种硬件平台的二进制机器码指令系统(即后来成为“字节码”的指令系统)。

以待语言开发成功后,能有半导体芯片生产商开发和生产这种硬件平台。对于新语言的设计,Sun公司研发人员并没有开发一种全新的语言,而是根据嵌入式软件的要求,对C++进行了改造,去除了留在C++的一些不太实用及影响安全的成分,并结合嵌入式系统的实时性要求,开发了一种称为Oak的面向对象语言。

android studio namevaluepair怎么导入

打开android studio2.0软件选择 File--> new--> Import Module...(注意不是 Import Project这个是导入项目又会启动一个窗口)

选择右边的按钮然后我们看到弹出了选择文件的对话框我们在电脑指定目录下找到我们需要导入的第三方类库然后点击OK

已经成功导入了第三方类库,按快捷键 Ctrl+Shift+Alt+S键或选择左上角的Flie-->project Structure...弹出一个对话我们选择右上角的”Dependcies“就可以看到下面我们添加的第三方类库了

namevaluepair(java里的“NameValuePair”是什么类型有什么用)

Java中的httpclient4.5应该怎么使用

一、所需要的jar包

httpclient-4.5.jar

httpcore-4.4.1.jar

httpmime-4.5.jar

二、实例

Java代码

package cn.tzz.apache.httpclient;

import java.io.File;

import java.io.IOException;

import java.net.URL;

import java.util.ArrayList;

import java.util.List;

import java.util.Map;

import org.apache.http.HttpEntity;

import org.apache.http.NameValuePair;

import org.apache.http.client.config.RequestConfig;

import org.apache.http.client.entity.UrlEncodedFormEntity;

import org.apache.http.client.methods.CloseableHttpResponse;

import org.apache.http.client.methods.HttpGet;

import org.apache.http.client.methods.HttpPost;

import org.apache.http.conn.ssl.DefaultHostnameVerifier;

import org.apache.http.conn.util.PublicSuffixMatcher;

import org.apache.http.conn.util.PublicSuffixMatcherLoader;

import org.apache.http.entity.ContentType;

import org.apache.http.entity.StringEntity;

import org.apache.http.entity.mime.MultipartEntityBuilder;

import org.apache.http.entity.mime.content.FileBody;

import org.apache.http.entity.mime.content.StringBody;

import org.apache.http.impl.client.CloseableHttpClient;

import org.apache.http.impl.client.HttpClients;

import org.apache.http.message.BasicNameValuePair;

import org.apache.http.util.EntityUtils;

public class HttpClientUtil{

private RequestConfig requestConfig= RequestConfig.custom()

.setSocketTimeout(15000)

.setConnectTimeout(15000)

.setConnectionRequestTimeout(15000)

.build();

private static HttpClientUtil instance= null;

private HttpClientUtil(){}

public static HttpClientUtil getInstance(){

if(instance== null){

instance= new HttpClientUtil();

}

return instance;

}

/**

*发送 post请求

*@param httpUrl地址

*/

public String sendHttpPost(String httpUrl){

HttpPost httpPost= new HttpPost(httpUrl);//创建httpPost

return sendHttpPost(httpPost);

}

/**

*发送 post请求

*@param httpUrl地址

*@param params参数(格式:key1=value1&key2=value2)

*/

public String sendHttpPost(String httpUrl, String params){

HttpPost httpPost= new HttpPost(httpUrl);//创建httpPost

try{

//设置参数

StringEntity stringEntity= new StringEntity(params,"UTF-8");

stringEntity.setContentType("application/x-www-form-urlencoded");

httpPost.setEntity(stringEntity);

} catch(Exception e){

e.printStackTrace();

}

return sendHttpPost(httpPost);

}

/**

*发送 post请求

*@param httpUrl地址

*@param maps参数

*/

public String sendHttpPost(String httpUrl, Map<String, String> maps){

HttpPost httpPost= new HttpPost(httpUrl);//创建httpPost

//创建参数队列

List<NameValuePair> nameValuePairs= new ArrayList<NameValuePair>();

for(String key: maps.keySet()){

nameValuePairs.add(new BasicNameValuePair(key, maps.get(key)));

}

try{

httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8"));

} catch(Exception e){

e.printStackTrace();

}

return sendHttpPost(httpPost);

}

/**

*发送 post请求(带文件)

*@param httpUrl地址

*@param maps参数

*@param fileLists附件

*/

public String sendHttpPost(String httpUrl, Map<String, String> maps, List<File> fileLists){

HttpPost httpPost= new HttpPost(httpUrl);//创建httpPost

MultipartEntityBuilder meBuilder= MultipartEntityBuilder.create();

for(String key: maps.keySet()){

meBuilder.addPart(key, new StringBody(maps.get(key), ContentType.TEXT_PLAIN));

}

for(File file: fileLists){

FileBody fileBody= new FileBody(file);

meBuilder.addPart("files", fileBody);

}

HttpEntity reqEntity= meBuilder.build();

httpPost.setEntity(reqEntity);

return sendHttpPost(httpPost);

}

/**

*发送Post请求

*@param httpPost

*@return

*/

private String sendHttpPost(HttpPost httpPost){

CloseableHttpClient httpClient= null;

CloseableHttpResponse response= null;

HttpEntity entity= null;

String responseContent= null;

try{

//创建默认的httpClient实例.

httpClient= HttpClients.createDefault();

httpPost.setConfig(requestConfig);

//执行请求

response= httpClient.execute(httpPost);

entity= response.getEntity();

responseContent= EntityUtils.toString(entity,"UTF-8");

} catch(Exception e){

e.printStackTrace();

} finally{

try{

//关闭连接,释放资源

if(response!= null){

response.close();

}

if(httpClient!= null){

httpClient.close();

}

} catch(IOException e){

e.printStackTrace();

}

}

return responseContent;

}

/**

*发送 get请求

*@param httpUrl

*/

public String sendHttpGet(String httpUrl){

HttpGet httpGet= new HttpGet(httpUrl);//创建get请求

return sendHttpGet(httpGet);

}

/**

*发送 get请求Https

*@param httpUrl

*/

public String sendHttpsGet(String httpUrl){

HttpGet httpGet= new HttpGet(httpUrl);//创建get请求

return sendHttpsGet(httpGet);

}

/**

*发送Get请求

*@param httpPost

*@return

*/

private String sendHttpGet(HttpGet httpGet){

CloseableHttpClient httpClient= null;

CloseableHttpResponse response= null;

HttpEntity entity= null;

String responseContent= null;

try{

//创建默认的httpClient实例.

httpClient= HttpClients.createDefault();

httpGet.setConfig(requestConfig);

//执行请求

response= httpClient.execute(httpGet);

entity= response.getEntity();

responseContent= EntityUtils.toString(entity,"UTF-8");

} catch(Exception e){

e.printStackTrace();

} finally{

try{

//关闭连接,释放资源

if(response!= null){

response.close();

}

if(httpClient!= null){

httpClient.close();

}

} catch(IOException e){

e.printStackTrace();

}

}

return responseContent;

}

/**

*发送Get请求Https

*@param httpPost

*@return

*/

private String sendHttpsGet(HttpGet httpGet){

CloseableHttpClient httpClient= null;

CloseableHttpResponse response= null;

HttpEntity entity= null;

String responseContent= null;

try{

//创建默认的httpClient实例.

PublicSuffixMatcher publicSuffixMatcher= PublicSuffixMatcherLoader.load(new URL(httpGet.getURI().toString()));

DefaultHostnameVerifier hostnameVerifier= new DefaultHostnameVerifier(publicSuffixMatcher);

httpClient= HttpClients.custom().setSSLHostnameVerifier(hostnameVerifier).build();

httpGet.setConfig(requestConfig);

//执行请求

response= httpClient.execute(httpGet);

entity= response.getEntity();

responseContent= EntityUtils.toString(entity,"UTF-8");

} catch(Exception e){

e.printStackTrace();

} finally{

try{

//关闭连接,释放资源

if(response!= null){

response.close();

}

if(httpClient!= null){

httpClient.close();

}

} catch(IOException e){

e.printStackTrace();

}

}

return responseContent;

}

}

好了,本文到此结束,如果可以帮助到大家,还望关注本站哦!

网上商城模板 怎么制作一个网页商城代理网站备案?网站代理备案是真的么