java - setconfig , setattribute and setheader cant be solved -
i'm developing anti theft application , connection http
class.
i have errors in couldn't solve ((cannot resolve setconfig , setattribute , setheader)) should resolve ?
here code :
package com.example.fatooma.location; /** * created fatooma on 26/07/2017. */ import java.io.bufferedreader; import java.io.inputstreamreader; import org.apache.http.httpresponse; import org.apache.http.httpstatus; import org.apache.http.httpversion; import org.apache.http.client.config.requestconfig; import org.apache.http.client.methods.httpget; import org.apache.http.client.protocol.httpclientcontext; import org.apache.http.impl.client.closeablehttpclient; import org.apache.http.impl.client.httpclients; import com.example.fatooma.location.core; public class httprmi { static string url = "http://localhost/projectserver"; closeablehttpclient httpclient = httpclients.createdefault(); // request configuration can overridden @ request level. // take precedence on 1 set @ client level. requestconfig requestconfig = requestconfig.custom().setsockettimeout(5000).setconnecttimeout(5000).setconnectionrequesttimeout(5000).build(); httpget httpget = new httpget(url); httpget.setconfig(requestconfig); httpget.setheader("user-agent","mozilla/5.0 (x11; u; linux x86_64; en-us; rv:1.9.2.13) gecko/20101206 firefox/3.6.13"); // execution context can customized locally. httpclientcontext context = httpclientcontext.create(); // contextual attributes set local context level take // precedence on set @ client level. context.setattribute("http.protocol.version",httpversion.http_1_1); try { // execute method httpresponse response = httpclient.execute(httpget); int statuscode = response.getstatusline().getstatuscode(); if (statuscode != httpstatus.sc_ok) { throw new illegalstateexception("method failed: " + response.getstatusline()); } bufferedreader br = new bufferedreader(new inputstreamreader((response.getentity().getcontent()))); stringbuffer buf = new stringbuffer(); string output; while ((output = br.readline()) != null) { buf.append(output); } content = buf.tostring(); } catch(exception e ) { throw e; } } httpclient.close() }}
Comments
Post a Comment