use of org.apache.http.params.BasicHttpParams in project ABPlayer by winkstu.
the class HttpUtil method httpGetCookie.
public static String httpGetCookie(String url) {
System.out.println("httpGetCookie" + url);
HttpGet httpget = new HttpGet(hostBase + url);
String strResult = "";
BasicHttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 15000);
HttpConnectionParams.setSoTimeout(httpParams, 15000);
try {
DefaultHttpClient httpClient = new DefaultHttpClient(httpParams);
httpClient.setRedirectHandler(new RedirectHandler() {
@Override
public boolean isRedirectRequested(HttpResponse response, HttpContext context) {
return false;
}
@Override
public URI getLocationURI(HttpResponse response, HttpContext context) throws ProtocolException {
return null;
}
});
httpget.setHeader("Cookie", cookieName + "=" + cookieValue);
HttpResponse response = httpClient.execute(httpget);
if (response.getStatusLine().getStatusCode() == 200) {
strResult = EntityUtils.toString(response.getEntity(), HTTP.UTF_8);
} else if (response.getStatusLine().getStatusCode() == 302) {
// cookieʧЧ�������ض����־�������µ�¼��ȡ
strResult = "302";
} else if (response.getStatusLine().getStatusCode() == 404) {
strResult = "-1";
}
} catch (Exception e) {
e.printStackTrace();
strResult = "4";
}
return strResult;
}
use of org.apache.http.params.BasicHttpParams in project ABPlayer by winkstu.
the class HttpUtil method httpPostCookie.
public static String httpPostCookie(String url, String id, String data) {
System.out.println("httpPostCookie" + url);
String result = "4";
HttpPost httpPost = new HttpPost(hostBase + url);
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("marc_no", id));
nvps.add(new BasicNameValuePair("r_content", data));
BasicHttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 10000);
HttpConnectionParams.setSoTimeout(httpParams, 10000);
try {
DefaultHttpClient httpClient = new DefaultHttpClient(httpParams);
httpClient.setRedirectHandler(new RedirectHandler() {
@Override
public boolean isRedirectRequested(HttpResponse response, HttpContext context) {
return false;
}
@Override
public URI getLocationURI(HttpResponse response, HttpContext context) throws ProtocolException {
return null;
}
});
httpPost.setHeader("Cookie", cookieName + "=" + cookieValue);
httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
HttpResponse response = httpClient.execute(httpPost);
System.out.println(response.getStatusLine().getStatusCode());
System.out.println(EntityUtils.toString(response.getEntity(), HTTP.UTF_8) + "add");
if (response.getStatusLine().getStatusCode() == 200) {
return "2";
} else if (response.getStatusLine().getStatusCode() == 302) {
Header[] headers = response.getHeaders("Location");
if (headers != null && headers.length > 0) {
System.out.println(headers[0].getValue());
return "3";
}
} else if (response.getStatusLine().getStatusCode() == 404) {
return "-1";
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
use of org.apache.http.params.BasicHttpParams in project newsrob by marianokamp.
the class CountingInputStream method newInstance.
public static NewsRobHttpClient newInstance(boolean followRedirects, Context ctx) {
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setStaleCheckingEnabled(params, true);
HttpConnectionParams.setConnectionTimeout(params, 45 * 1000);
HttpConnectionParams.setSoTimeout(params, 45 * 1000);
HttpConnectionParams.setSocketBufferSize(params, 8192);
// HttpConnectionParams.setTcpNoDelay(params, true);
// Don't handle redirects -- return them to the caller. Our code
// often wants to re-POST after a redirect, which we must do ourselves.
// HttpClientParams.setRedirecting(params, false);
HttpClientParams.setRedirecting(params, followRedirects);
if (followRedirects)
params.setIntParameter(ClientPNames.MAX_REDIRECTS, 10);
// Set the specified user agent and register standard protocols.
HttpProtocolParams.setUserAgent(params, USER_AGENT);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);
// parameters without the funny call-a-static-method dance.
return new NewsRobHttpClient(manager, params, ctx);
}
use of org.apache.http.params.BasicHttpParams in project platform_external_apache-http by android.
the class DefaultHttpClient method createHttpParams.
@Override
protected HttpParams createHttpParams() {
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
/*
* Android note: Send each request body without first asking the server
* whether it will be accepted. Asking first slows down the common case
* and results in "417 expectation failed" errors when a HTTP/1.0 server
* is behind a proxy. http://b/2471595
*/
HttpProtocolParams.setUseExpectContinue(params, // android-changed
false);
// determine the release version from packaged version info
final VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client", getClass().getClassLoader());
final String release = (vi != null) ? vi.getRelease() : VersionInfo.UNAVAILABLE;
HttpProtocolParams.setUserAgent(params, "Apache-HttpClient/" + release + " (java 1.4)");
return params;
}
use of org.apache.http.params.BasicHttpParams in project tdi-studio-se by Talend.
the class DeviceIdManager method executeRegistrationRequest.
/**
* This method demonstrate execution of device registration request.
*
* @param url Registration uri
* @param soapEnvelope Registration xml envelope
* @return device registration puid
*/
private static String executeRegistrationRequest(String url, String soapEnvelope) throws IllegalStateException, SAXException, ParserConfigurationException, DeviceRegistrationFailedException, IOException {
HttpResponse response = null;
// Create the request that will submit the request to the server
try {
HttpParams params = new BasicHttpParams();
params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 180000);
HttpClient client = new SystemDefaultHttpClient(params);
// Uncomment following lines to view the traffic in fiddler.
// HttpHost proxy = new HttpHost("localhost", 8888);
// client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
HttpPost post = new HttpPost(url);
StringEntity entity = new StringEntity(soapEnvelope);
post.setHeader("Content-Type", "application/soap+xml; charset=UTF-8");
post.setEntity(entity);
response = client.execute(post);
return parseRegistrationResponse(response, false);
} catch (ClientProtocolException e) {
Log.error(e.getMessage());
parseRegistrationResponse(response, true);
throw e;
} catch (IOException e) {
Log.error(e.getMessage());
parseRegistrationResponse(response, true);
throw e;
}
}
Aggregations