@@ -27,20 +27,22 @@ public BasicHttpResponse handlerRequest(Request<?> request) throws IOException {
27
27
//System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
28
28
URL url = new URL (request .getUrl ());
29
29
HttpURLConnection connection = (HttpURLConnection )url .openConnection ();
30
- for (Entry <String ,String > entry : request .getHeader ().entrySet ()){
31
- connection .addRequestProperty (entry .getKey (), entry .getValue ());
30
+ if (request .getHeader () != null ){
31
+ for (Entry <String ,String > entry : request .getHeader ().entrySet ()){
32
+ connection .addRequestProperty (entry .getKey (), entry .getValue ());
33
+ }
34
+ if (request .getEtag () != null ){
35
+ connection .addRequestProperty ("If-None-Match" ,request .getEtag ());
36
+ }
37
+ if (request .getiMS () != null ){
38
+ connection .addRequestProperty ("If-Modified-Since" ,request .getEtag ());
39
+ }
32
40
}
33
- if (request .getEtag () != null ){
34
- connection .addRequestProperty ("If-None-Match" ,request .getEtag ());
35
- }
36
- if (request .getiMS () != null ){
37
- connection .addRequestProperty ("If-Modified-Since" ,request .getEtag ());
38
- }
39
41
setPostParams (request ,connection );
40
42
ProtocolVersion protocolVersion = new ProtocolVersion ("HTTP" , 1 , 1 );
41
43
int responseCode = connection .getResponseCode ();
42
44
if (responseCode == -1 ) {
43
- throw new IOException ("Á¬½Óʧ°Ü " );
45
+ throw new IOException ("连接失败 " );
44
46
}
45
47
StatusLine responseStatus = new BasicStatusLine (protocolVersion ,
46
48
connection .getResponseCode (), connection .getResponseMessage ());
@@ -69,6 +71,9 @@ private void setPostParams(Request<?> request, HttpURLConnection connection) thr
69
71
connection .getOutputStream ();
70
72
DataOutputStream out = new DataOutputStream (connection .getOutputStream ());
71
73
Map <String ,String > map = request .getParam ();
74
+ if (map == null ){
75
+ return ;
76
+ }
72
77
String params = null ;
73
78
int record = 0 ;
74
79
int size = map .entrySet ().size ();
0 commit comments