Skip to content

Commit 84440b4

Browse files
committed
created addHeader method in post
1 parent 6f4b447 commit 84440b4

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/http/requests/PostRequest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class PostRequest
2626
String url;
2727
ArrayList<BasicNameValuePair> nameValuePairs;
2828
HashMap<String,File> nameFilePairs;
29+
ArrayList<BasicNameValuePair> headerPairs;
30+
2931

3032
String content;
3133
String encoding;
@@ -49,6 +51,12 @@ public void addUser(String user, String pwd)
4951
{
5052
creds = new UsernamePasswordCredentials(user, pwd);
5153
}
54+
55+
public void addHeader(String key,String value) {
56+
BasicNameValuePair nvp = new BasicNameValuePair(key,value);
57+
headerPairs.add(nvp);
58+
59+
}
5260

5361
public void addData(String key, String value)
5462
{
@@ -92,6 +100,12 @@ public void send()
92100
httpPost.setEntity(mentity);
93101
}
94102

103+
Iterator<BasicNameValuePair> headerIterator = headerPairs.iterator();
104+
while (headerIterator.hasNext()) {
105+
BasicNameValuePair headerPair = headerIterator.next();
106+
httpPost.addHeader(headerPair.getName(),headerPair.getValue());
107+
}
108+
95109
response = httpClient.execute( httpPost );
96110
HttpEntity entity = response.getEntity();
97111
this.content = EntityUtils.toString(response.getEntity());

0 commit comments

Comments
 (0)