user383343
user383343

Reputation: 851

How make an array of org.apache.http.Header?

I'm new in Java.

I'm trying to do

import org.apache.http.Header;
Header<NameValuePair> nvps = new HeaderList<NameValuePair>();
//....adding some headers
httppost.setHeaders(nvps);

but said

The type Header is not generic; it cannot be parameterized with arguments <NameValuePair>

how I can do it?

Upvotes: 14

Views: 20595

Answers (3)

manoj
manoj

Reputation: 3781

use this way

import org.apache.http.protocol.HTTP;
import org.apache.http.entity.ContentType;
import org.apache.http.message.BasicHeader
....

Header[] headers = {new BasicHeader(HTTP.CONTENT_TYPE, 
         ContentType.APPLICATION_JSON.toString())};
...

Upvotes: 1

user383343
user383343

Reputation: 851

I found the answer

Header[] headers = {
    new BasicHeader("Content-type", "application/x-www-form-urlencoded")
    ,new BasicHeader("Content-type", "application/x-www-form-urlencoded")
    ,new BasicHeader("Accep", "text/html,text/xml,application/xml")
    ,new BasicHeader("Connection", "keep-alive")
    ,new BasicHeader("keep-alive", "115")
    ,new BasicHeader("User-Agent", "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2")
};

Upvotes: 53

sarahTheButterFly
sarahTheButterFly

Reputation: 1952

I've never used org.apache.http.* before, so I had a look at the API. From there I can see that Header is an interface and 'org.apache.http.message.BasicHeader' is one of its implementation. so maybe you'd like to use this type instead. Also I couldn't find HeaderList in the package.

Upvotes: 3

Related Questions