Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
webmagic
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
沈俊林
webmagic
Commits
c3bdb204
Commit
c3bdb204
authored
Jul 22, 2017
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#631 remove IllegalArgumentException of HttpRequestBody.json and so on
parent
486a6d5c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
7 deletions
+19
-7
HttpRequestBody.java
...ain/java/us/codecraft/webmagic/model/HttpRequestBody.java
+19
-7
No files found.
webmagic-core/src/main/java/us/codecraft/webmagic/model/HttpRequestBody.java
View file @
c3bdb204
...
...
@@ -64,24 +64,36 @@ public class HttpRequestBody implements Serializable {
this
.
encoding
=
encoding
;
}
public
static
HttpRequestBody
json
(
String
json
,
String
encoding
)
throws
UnsupportedEncodingException
{
return
new
HttpRequestBody
(
json
.
getBytes
(
encoding
),
ContentType
.
JSON
,
encoding
);
public
static
HttpRequestBody
json
(
String
json
,
String
encoding
)
{
try
{
return
new
HttpRequestBody
(
json
.
getBytes
(
encoding
),
ContentType
.
JSON
,
encoding
);
}
catch
(
UnsupportedEncodingException
e
)
{
throw
new
IllegalArgumentException
(
"illegal encoding "
+
encoding
,
e
);
}
}
public
static
HttpRequestBody
xml
(
String
xml
,
String
encoding
)
throws
UnsupportedEncodingException
{
return
new
HttpRequestBody
(
xml
.
getBytes
(
encoding
),
ContentType
.
XML
,
encoding
);
public
static
HttpRequestBody
xml
(
String
xml
,
String
encoding
)
{
try
{
return
new
HttpRequestBody
(
xml
.
getBytes
(
encoding
),
ContentType
.
XML
,
encoding
);
}
catch
(
UnsupportedEncodingException
e
)
{
throw
new
IllegalArgumentException
(
"illegal encoding "
+
encoding
,
e
);
}
}
public
static
HttpRequestBody
custom
(
byte
[]
body
,
String
contentType
,
String
encoding
)
throws
UnsupportedEncodingException
{
public
static
HttpRequestBody
custom
(
byte
[]
body
,
String
contentType
,
String
encoding
)
{
return
new
HttpRequestBody
(
body
,
contentType
,
encoding
);
}
public
static
HttpRequestBody
form
(
Map
<
String
,
Object
>
params
,
String
encoding
)
throws
UnsupportedEncodingException
{
public
static
HttpRequestBody
form
(
Map
<
String
,
Object
>
params
,
String
encoding
){
List
<
NameValuePair
>
nameValuePairs
=
new
ArrayList
<
NameValuePair
>(
params
.
size
());
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
params
.
entrySet
())
{
nameValuePairs
.
add
(
new
BasicNameValuePair
(
entry
.
getKey
(),
String
.
valueOf
(
entry
.
getValue
())));
}
return
new
HttpRequestBody
(
URLEncodedUtils
.
format
(
nameValuePairs
,
encoding
).
getBytes
(
encoding
),
ContentType
.
FORM
,
encoding
);
try
{
return
new
HttpRequestBody
(
URLEncodedUtils
.
format
(
nameValuePairs
,
encoding
).
getBytes
(
encoding
),
ContentType
.
FORM
,
encoding
);
}
catch
(
UnsupportedEncodingException
e
)
{
throw
new
IllegalArgumentException
(
"illegal encoding "
+
encoding
,
e
);
}
}
public
byte
[]
getBody
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment