本文整理汇总了Java中org.apache.http.params.CoreProtocolPNames类的典型用法代码示例。如果您正苦于以下问题:Java CoreProtocolPNames类的具体用法?Java CoreProtocolPNames怎么用?Java CoreProtocolPNames使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CoreProtocolPNames类属于org.apache.http.params包,在下文中一共展示了CoreProtocolPNames类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newAsyncHttpClient
import org.apache.http.params.CoreProtocolPNames; //导入依赖的package包/类
/**
* 全局唯一的AsyncHttpClient对象
*
* @return
*/
public static AsyncHttpClient newAsyncHttpClient()
{
String userAgent = null;
if (CDK.getInstance().getCDKContext() != null)
{
userAgent = CDK.getInstance().getCDKContext().getUserAgent();
}
if (userAgent == null)
{
userAgent = "Mozilla/5.0 (Linux; U; Android 4.3; zh-cn; GT-I9300 Build/JSS15J) "
+ "AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.3022";
}
asyncHttpClient.getHttpClient().getParams().setParameter(CoreProtocolPNames.USER_AGENT, userAgent + ".10");
return asyncHttpClient;
}
示例2: QSystemHtmlInstance
import org.apache.http.params.CoreProtocolPNames; //导入依赖的package包/类
private QSystemHtmlInstance() {
this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000).
setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024).
setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false).
setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true).
setParameter(CoreProtocolPNames.ORIGIN_SERVER, "QSystemReportHttpServer/1.1");
// Set up the HTTP protocol processor
final BasicHttpProcessor httpproc = new BasicHttpProcessor();
httpproc.addInterceptor(new ResponseDate());
httpproc.addInterceptor(new ResponseServer());
httpproc.addInterceptor(new ResponseContent());
httpproc.addInterceptor(new ResponseConnControl());
// Set up request handlers
final HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
reqistry.register("*", new HttpQSystemReportsHandler());
// Set up the HTTP service
this.httpService = new HttpService(
httpproc,
new DefaultConnectionReuseStrategy(),
new DefaultHttpResponseFactory(), reqistry, this.params);
}
示例3: RequestListenerThread
import org.apache.http.params.CoreProtocolPNames; //导入依赖的package包/类
public RequestListenerThread(Context context) throws IOException, BindException {
serversocket = new ServerSocket(PORT);
params = new BasicHttpParams();
params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000).setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true).setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
// Set up the HTTP protocol processor
BasicHttpProcessor httpProcessor = new BasicHttpProcessor();
httpProcessor.addInterceptor(new ResponseDate());
httpProcessor.addInterceptor(new ResponseServer());
httpProcessor.addInterceptor(new ResponseContent());
httpProcessor.addInterceptor(new ResponseConnControl());
// Set up the HTTP service
this.httpService = new YaaccHttpService(httpProcessor, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory(), context);
}
示例4: process
import org.apache.http.params.CoreProtocolPNames; //导入依赖的package包/类
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
Args.notNull(request, "HTTP request");
if (!request.containsHeader(HTTP.USER_AGENT)) {
String s = null;
final HttpParams params = request.getParams();
if (params != null) {
s = (String) params.getParameter(CoreProtocolPNames.USER_AGENT);
}
if (s == null) {
s = this.userAgent;
}
if (s != null) {
request.addHeader(HTTP.USER_AGENT, s);
}
}
}
示例5: newAsyncHttpClient
import org.apache.http.params.CoreProtocolPNames; //导入依赖的package包/类
/**
* 全局唯一的AsyncHttpClient对象
*
* @return
*/
public static AsyncHttpClient newAsyncHttpClient()
{
String userAgent = null;
if (RockySdk.getInstance().getClientInfo() != null)
{
userAgent = RockySdk.getInstance().getClientInfo().getUserAgent();
}
if (userAgent == null)
{
userAgent = "Mozilla/5.0 (Linux; U; Android 4.3; zh-cn; GT-I9300 Build/JSS15J) "
+ "AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.3022";
}
asyncHttpClient.getHttpClient().getParams().setParameter(CoreProtocolPNames.USER_AGENT, userAgent + ".10");
return asyncHttpClient;
}
示例6: postCookie
import org.apache.http.params.CoreProtocolPNames; //导入依赖的package包/类
public int postCookie(String data) throws Exception {
HttpPost httpPost = new HttpPost(URL.toString());
System.out.println("change user agent");
HttpContext HTTP_CONTEXT = new BasicHttpContext();
client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13");
HTTP_CONTEXT.setAttribute(CoreProtocolPNames.USER_AGENT, "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13");
httpPost.setHeader("User-Agent", "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13");
if (isAuthByPrivateKey) httpPost.setHeaders(headersArray);
// httpPost.addHeader("Content-Type","application/json")
// httpPost.addHeader("host",this.host)
log.debug("Post send :" + data.replace("\n", ""));
//write data
BasicHttpEntity entity = new BasicHttpEntity();
entity.setContent(new ByteArrayInputStream(data.getBytes()));
entity.setContentLength((long)data.getBytes().length);
httpPost.setEntity(entity);
response = client.execute(targetHost, httpPost, localcontext);
return response.getStatusLine().getStatusCode();
}
示例7: RequestListenerThread
import org.apache.http.params.CoreProtocolPNames; //导入依赖的package包/类
public RequestListenerThread(int port, final String docroot) throws IOException {
this.serversocket = new ServerSocket(port);
this.params = new SyncBasicHttpParams();
this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000).setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024).setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false).setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true).setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
// Set up the HTTP protocol processor
HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[]{
new ResponseDate(),
new ResponseServer(),
new ResponseContent(),
new ResponseConnControl()
});
// Set up request handlers
HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
reqistry.register("*", new HttpFileHandler());
// Set up the HTTP service
this.httpService = new HttpService(
httpproc,
new DefaultConnectionReuseStrategy(),
new DefaultHttpResponseFactory(),
reqistry,
this.params);
}
示例8: get_url_contents
import org.apache.http.params.CoreProtocolPNames; //导入依赖的package包/类
String get_url_contents( String url , List<NameValuePair> params , CookieStore cookieStore ) {
try {
HttpClient client = MySSLSocketFactory.createMyHttpClient();
client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT);
HttpResponse response = null;
if( cookieStore == null )
response = client.execute( new HttpGet( params == null || params.size() == 0 ? url : url + "?" + URLEncodedUtils.format(params, "utf-8") ) );
else {
HttpContext mHttpContext = new BasicHttpContext();
mHttpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
response = client.execute( new HttpGet( params == null || params.size() == 0 ? url : url + "?" + URLEncodedUtils.format(params, "utf-8") ) , mHttpContext );
}
HttpEntity result = response.getEntity();
if( result != null ) {
InputStream mInputStream = result.getContent();
String out = getStringFromInputStream(mInputStream);
mInputStream.close();
return out;
}
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
示例9: getRequestParams
import org.apache.http.params.CoreProtocolPNames; //导入依赖的package包/类
protected HttpParams getRequestParams(StreamRequestMessage requestMessage) {
HttpParams localParams = new BasicHttpParams();
localParams.setParameter(
CoreProtocolPNames.PROTOCOL_VERSION,
requestMessage.getOperation().getHttpMinorVersion() == 0 ? HttpVersion.HTTP_1_0 : HttpVersion.HTTP_1_1
);
// DefaultHttpClient adds HOST header automatically in its default processor
// Let's add the user-agent header on every request
HttpProtocolParams.setUserAgent(
localParams,
getConfiguration().getUserAgentValue(requestMessage.getUdaMajorVersion(), requestMessage.getUdaMinorVersion())
);
return new DefaultedHttpParams(localParams, globalParams);
}
示例10: getDefaultHttpClient
import org.apache.http.params.CoreProtocolPNames; //导入依赖的package包/类
/**
* 获取DefaultHttpClient对象
*
* @param charset
* 字符编码
* @return DefaultHttpClient对象
*/
private static DefaultHttpClient getDefaultHttpClient(final String charset) {
DefaultHttpClient httpclient = new DefaultHttpClient();
// 模拟浏览器,解决一些服务器程序只允许浏览器访问的问题
httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT,
USER_AGENT);
httpclient.getParams().setParameter(
CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE);
httpclient.getParams().setParameter(
CoreProtocolPNames.HTTP_CONTENT_CHARSET,
charset == null ? CHARSET_ENCODING : charset);
// 浏览器兼容性
httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY,
CookiePolicy.BROWSER_COMPATIBILITY);
// 定义重试策略
httpclient.setHttpRequestRetryHandler(requestRetryHandler);
return httpclient;
}
示例11: getRequestParams
import org.apache.http.params.CoreProtocolPNames; //导入依赖的package包/类
protected HttpParams getRequestParams(StreamRequestMessage requestMessage) {
HttpParams localParams = new BasicHttpParams();
localParams.setParameter(
CoreProtocolPNames.PROTOCOL_VERSION,
requestMessage.getOperation().getHttpMinorVersion() == 0 ? HttpVersion.HTTP_1_0 : HttpVersion.HTTP_1_1
);
// DefaultHttpClient adds HOST header automatically in its default processor
// Add the default user agent if not already set on the message
if (!requestMessage.getHeaders().containsKey(UpnpHeader.Type.USER_AGENT)) {
HttpProtocolParams.setUserAgent(
localParams,
getConfiguration().getUserAgentValue(requestMessage.getUdaMajorVersion(), requestMessage.getUdaMinorVersion())
);
}
return new DefaultedHttpParams(localParams, globalParams);
}
示例12: fileUpload
import org.apache.http.params.CoreProtocolPNames; //导入依赖的package包/类
public static void fileUpload() throws IOException {
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost httppost = new HttpPost(postURL);
File file = new File("d:/hai.html");
System.out.println(ukeycookie);
httppost.setHeader("Cookie", ukeycookie + ";" + skeycookie + ";" + usercookie);
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbFile = new FileBody(file);
mpEntity.addPart("", cbFile);
httppost.setEntity(mpEntity);
System.out.println("Now uploading your file into mediafire...........................");
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
System.out.println(response.getStatusLine());
if (resEntity != null) {
System.out.println("Getting upload response key value..........");
uploadresponsekey = EntityUtils.toString(resEntity);
getUploadResponseKey();
System.out.println("upload resoponse key " + uploadresponsekey);
}
}
示例13: fileUpload
import org.apache.http.params.CoreProtocolPNames; //导入依赖的package包/类
public static void fileUpload() throws IOException {
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
file = new File("/home/vigneshwaran/dinesh.txt");
HttpPost httppost = new HttpPost(postURL);
httppost.setHeader("Cookie", langcookie + ";" + sessioncookie + ";" + mailcookie + ";" + namecookie + ";" + rolecookie + ";" + orderbycookie + ";" + directioncookie + ";");
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbFile = new FileBody(file);
mpEntity.addPart("files[]", cbFile);
httppost.setEntity(mpEntity);
System.out.println("Now uploading your file into wupload...........................");
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
System.out.println(response.getStatusLine());
if (response.getStatusLine().getStatusCode() == 302
&& response.getFirstHeader("Location").getValue().contains("upload/done/")) {
System.out.println("Upload successful :)");
} else {
System.out.println("Upload failed :(");
}
}
示例14: fileUpload
import org.apache.http.params.CoreProtocolPNames; //导入依赖的package包/类
public static void fileUpload() throws IOException {
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
file = new File("C:\\Documents and Settings\\dinesh\\Desktop\\GeDotttUploaderPlugin.java");
HttpPost httppost = new HttpPost("https://docs.zoho.com/uploadsingle.do?isUploadStatus=false&folderId=0&refFileElementId=refFileElement0");
httppost.setHeader("Cookie", cookies.toString());
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbFile = new FileBody(file);
mpEntity.addPart("multiupload_file", cbFile);
httppost.setEntity(mpEntity);
System.out.println("Now uploading your file into zoho docs...........................");
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
System.out.println(response.getStatusLine());
if (resEntity != null) {
String tmp = EntityUtils.toString(resEntity);
// System.out.println(tmp);
if(tmp.contains("File Uploaded Successfully"))
System.out.println("File Uploaded Successfully");
}
// uploadresponse = response.getLastHeader("Location").getValue();
// System.out.println("Upload response : " + uploadresponse);
}
示例15: HttpServer
import org.apache.http.params.CoreProtocolPNames; //导入依赖的package包/类
private HttpServer(WifiManager wifiManager) {
this.wifiManager = wifiManager;
this.listenPort = 0;
this.handlerRegistry = new HttpRequestHandlerRegistry();
this.params = new BasicHttpParams();
this.params
.setParameter(CoreProtocolPNames.ORIGIN_SERVER,
"4thLineAndroidHttpServer/1.0")
.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE,
8 * 1024)
.setBooleanParameter(
CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true);
startServer();
}