protected
static
String HttpPOST(String url, String strjson) {
String result =
"0"
, encode =
"UTF-8"
;
try
{
URL u =
new
URL(url);
HttpURLConnection httpconn = (HttpURLConnection) u.openConnection();
httpconn.setDoOutput(
true
);
httpconn.setDoInput(
true
);
httpconn.setUseCaches(
false
);
httpconn.setRequestMethod(
"POST"
);
String requestString = strjson;
byte
[] bytes = requestString.getBytes(
"UTF-8"
);
httpconn.setRequestProperty(
"Content-length"
,
""
+ bytes.length);
httpconn.setRequestProperty(
"Content-Type"
,
"application/json"
);
httpconn.setRequestProperty(
"Connection"
,
"Keep-Alive"
);
httpconn.setRequestProperty(
"Charset"
, encode);
OutputStream outputStream = httpconn.getOutputStream();
outputStream.write(bytes);
outputStream.close();
int
responseCode = httpconn.getResponseCode();
if
(HttpURLConnection.HTTP_OK == responseCode) {
StringBuffer sb =
new
StringBuffer();
String readLine;
BufferedReader responseReader;
responseReader =
new
BufferedReader(
new
InputStreamReader(
httpconn.getInputStream(), encode));
while
((readLine = responseReader.readLine()) !=
null
) {
sb.append(readLine);
}
result = sb.toString();
responseReader.close();
}
}
catch
(Exception e) {
result =
"-9"
;
}
return
result;
}