本文整理汇总了Java中javax.net.ssl.HttpsURLConnection.HTTP_OK属性的典型用法代码示例。如果您正苦于以下问题:Java HttpsURLConnection.HTTP_OK属性的具体用法?Java HttpsURLConnection.HTTP_OK怎么用?Java HttpsURLConnection.HTTP_OK使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.net.ssl.HttpsURLConnection
的用法示例。
在下文中一共展示了HttpsURLConnection.HTTP_OK属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doInBackground
@Override
protected String doInBackground(String... params) {
try
{
URL whatismyip = new URL("http://checkip.amazonaws.com");
BufferedReader input = new BufferedReader(new InputStreamReader(whatismyip.openStream()));
ip = input.readLine();
HttpURLConnection connection = (HttpURLConnection) new URL("http://ip-api.com/json/" + ip).openConnection();
connection.setReadTimeout(3000);
connection.setConnectTimeout(3000);
connection.setRequestMethod("GET");
connection.setDoInput(true);
connection.connect();
int responseCode = connection.getResponseCode();
if (responseCode != HttpsURLConnection.HTTP_OK) {
throw new IOException("HTTP error code: " + responseCode);
}
InputStream in = new java.io.BufferedInputStream(connection.getInputStream());
//s=readStream(in,10000);
s=convertStreamToString(in);
Log.d("MainActivity", "Call reached here");
if (in != null) {
// Converts Stream to String with max length of 500.
Log.d("MainActivity call 2", s);
}
} catch (Exception e) {
e.printStackTrace();
}
return s;
}
示例2: doInBackground
@Override
protected String doInBackground(String... params)
{
try
{
String p1 = URLEncoder.encode(nameValue,"utf-8");
String p2 = URLEncoder.encode(messageValue,"utf-8");
String ur = "http://akash-deep.in/contact-process.jsp?" +
"Name="+p1+"&Email="+emailvalue+"&phone="+phoneValue+"&Message="+p2+"";
HttpURLConnection connection = (HttpURLConnection) new URL(ur).openConnection();
// Toast.makeText(getActivity(),ur,Toast.LENGTH_SHORT).show();
Log.d("myurla",ur);
connection.setReadTimeout(3000);
connection.setConnectTimeout(3000);
connection.setRequestMethod("POST");
connection.setDoInput(true);
connection.connect();
int responseCode = connection.getResponseCode();
if (responseCode != HttpsURLConnection.HTTP_OK) {
throw new IOException("HTTP error code: " + responseCode);
}
InputStream in = new java.io.BufferedInputStream(connection.getInputStream());
s = convertStreamToString(in);
//pd.dismiss();
}
catch (Exception e) {
e.printStackTrace();
}
return s;
}
示例3: getResponseContent
/**
* Get Response Content : this method evaluate the response based on the HTTP_CODE and extract
* the content of the reponse
* @param response A variable of type Object (Could be String or ResponseError)
* @return
*/
Object getResponseContent(Response response){
if(response == null)
return new ResponseError(ResponseCode.HTTP_TIME_OUT, "Unable to connect to Nyris services, check your internet connection.");
String content = null;
try {
content = response.body().string();
} catch (IOException e) {
e.printStackTrace();
}
Log.i("error code : "+response.code(),content);
switch (response.code()){
case HttpsURLConnection.HTTP_OK:
case HttpsURLConnection.HTTP_CREATED:
case HttpsURLConnection.HTTP_NO_CONTENT:
case HttpsURLConnection.HTTP_ACCEPTED:
return content ;
default:
ResponseError responseError = null;
try {
Gson gson = new Gson();
responseError = gson.fromJson(content.toString(), ResponseError.class);
}
catch (Exception ignored){}
if(responseError == null || responseError.getErrorCode() == null){
responseError = new ResponseError();
responseError.setErrorCode(convertErrorResponseCode(response));
String message = response.message();
if(message == null || message.isEmpty())
message = "Unknown Error";
responseError.setErrorDescription(message);
}
return responseError;
}
}
示例4: doInBackground
@Override
protected String doInBackground(String... params) {
String reqString = params[0];
String response = "";
try{
URL reqURL = new URL(reqString);
HttpsURLConnection conn = (HttpsURLConnection)reqURL.openConnection();
JSONObject tokenObject = new JSONObject();
byte[] requestBytes = null;
tokenObject.put("_token", mRequestor.getToken());
requestBytes = tokenObject.toString().getBytes();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setChunkedStreamingMode(0);
conn.setRequestProperty("Content-Type", "application/json");
OutputStream os = conn.getOutputStream();
os.write(requestBytes);
int responseCode = conn.getResponseCode();
if (responseCode == HttpsURLConnection.HTTP_OK) {
String line;
BufferedReader br = new BufferedReader(new InputStreamReader(
conn.getInputStream()));
while ((line = br.readLine()) != null) {
response += line;
}
} else {
response = "";
}
}
catch (IOException|JSONException ex){
ex.printStackTrace();
}
return response;
}
示例5: doInBackground
@Override
protected String doInBackground(String... params) {
try
{
URL whatismyip = new URL("http://checkip.amazonaws.com");
BufferedReader input = new BufferedReader(new InputStreamReader(whatismyip.openStream()));
ip = input.readLine();
HttpURLConnection connection = (HttpURLConnection) new URL("http://ip-api.com/json/" + ip).openConnection();
connection.setReadTimeout(3000);
connection.setConnectTimeout(3000);
connection.setRequestMethod("GET");
connection.setDoInput(true);
connection.connect();
int responseCode = connection.getResponseCode();
if (responseCode != HttpsURLConnection.HTTP_OK) {
throw new IOException("HTTP error code: " + responseCode);
}
InputStream in = new java.io.BufferedInputStream(connection.getInputStream());
//s=readStream(in,10000);
s=convertStreamToString(in);
jsonObject=new JSONObject(s);
city=jsonObject.getString("city");
isp=jsonObject.getString("org");
state=jsonObject.getString("regionName");
country=jsonObject.getString("country");
Log.d("MainActivity", "Call reached here");
if (in != null) {
// Converts Stream to String with max length of 500.
Log.d("MainActivity call 2", s);
}
} catch (Exception e) {
e.printStackTrace();
}
return s;
}