类org.apache.http.params.CoreProtocolPNames源码实例Demo

下面列出了怎么用org.apache.http.params.CoreProtocolPNames的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: TVRemoteIME   文件: StreamClientImpl.java
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);
}
 
/**
 * 全局唯一的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;
}
 
源代码3 项目: AndroidRobot   文件: HttpClientUtil.java
/** 
 * 获取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;  
}
 
源代码4 项目: DroidDLNA   文件: StreamClientImpl.java
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);
}
 
源代码5 项目: neembuu-uploader   文件: MediaFireUploadPlugin.java
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);
    }
}
 
源代码6 项目: neembuu-uploader   文件: WuploadUploaderPlugin.java
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 :(");
    }

}
 
源代码7 项目: neembuu-uploader   文件: ZohoDocsUploaderPlugin.java
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);
    }
 
@Override
public DefaultHttpClient create(final HttpMethod method, final URI uri) {
  final TrustStrategy acceptTrustStrategy = new TrustStrategy() {
    @Override
    public boolean isTrusted(final X509Certificate[] certificate, final String authType) {
      return true;
    }
  };

  final SchemeRegistry registry = new SchemeRegistry();
  try {
    final SSLSocketFactory ssf =
            new SSLSocketFactory(acceptTrustStrategy, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    registry.register(new Scheme(uri.getScheme(), uri.getPort(), ssf));
  } catch (Exception e) {
    throw new ODataRuntimeException(e);
  }

  final DefaultHttpClient httpClient = new DefaultHttpClient(new BasicClientConnectionManager(registry));
  httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT);

  return httpClient;
}
 
源代码9 项目: h2o-2   文件: GoogleAnalytics.java
protected HttpClient createHttpClient(GoogleAnalyticsConfig config) {
  ThreadSafeClientConnManager connManager = new ThreadSafeClientConnManager();
  connManager.setDefaultMaxPerRoute(getDefaultMaxPerRoute(config));

  BasicHttpParams params = new BasicHttpParams();

  if (isNotEmpty(config.getUserAgent())) {
    params.setParameter(CoreProtocolPNames.USER_AGENT, config.getUserAgent());
  }

  if (isNotEmpty(config.getProxyHost())) {
    params.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(config.getProxyHost(), config.getProxyPort()));
  }

  DefaultHttpClient client = new DefaultHttpClient(connManager, params);

  if (isNotEmpty(config.getProxyUserName())) {
    BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope(config.getProxyHost(), config.getProxyPort()),
            new UsernamePasswordCredentials(config.getProxyUserName(), config.getProxyPassword()));
    client.setCredentialsProvider(credentialsProvider);
  }

  return client;
}
 
源代码10 项目: openhab1-addons   文件: HttpComponentsHelper.java
/**
 * prepare for the https connection
 * call this in the constructor of the class that does the connection if
 * it's used multiple times
 */
private void setup() {
    SchemeRegistry schemeRegistry = new SchemeRegistry();

    // http scheme
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    // https scheme
    schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));

    params = new BasicHttpParams();
    params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 1);
    params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(1));
    params.setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "utf8");

    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    // set the user credentials for our site "example.com"
    credentialsProvider.setCredentials(new AuthScope("example.com", AuthScope.ANY_PORT),
            new UsernamePasswordCredentials("UserNameHere", "UserPasswordHere"));
    clientConnectionManager = new ThreadSafeClientConnManager(params, schemeRegistry);

    context = new BasicHttpContext();
    context.setAttribute("http.auth.credentials-provider", credentialsProvider);
}
 
public static void main(String[] args) {
    if (args.length == 2) {
        try {
            String filename = args[0];
            String url = args[1];

            DefaultHttpClient client = new DefaultHttpClient();
            client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
            upload(filename, url, client);
            client.getConnectionManager().shutdown();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        System.out.println("Usage: import_usage_point.sh filename url");
        System.out.println("");
        System.out.println("Example:");
        System.out.println("");
        System.out.println("  import_usage_point.sh etc/usage_point.xml http://localhost:8080/custodian/retailcustomers/1/upload");
    }
}
 
@Test
public void sendHttpOneZeroRequest() throws IOException {
    TestHttpClient client = new TestHttpClient();
    try {
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path");
        get.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Header[] header = result.getHeaders("MyHeader");
        Assert.assertEquals("MyValue", header[0].getValue());
    } finally {
        client.getConnectionManager().shutdown();
    }
}
 
源代码13 项目: quarkus   文件: AccessLogFileTestCase.java
@Test
public void testSingleLogMessageToFile() throws IOException, InterruptedException {
    // issue the request with a specific HTTP protocol version, so that we can then verify
    // the protocol value logged in the access log file
    final RestAssuredConfig http10Config = RestAssured.config().httpClient(
            new HttpClientConfig().setParam(CoreProtocolPNames.PROTOCOL_VERSION, new ProtocolVersion("HTTP", 1, 0)));
    final RequestSpecification requestSpec = new RequestSpecBuilder().setConfig(http10Config).build();
    final String paramValue = UUID.randomUUID().toString();
    RestAssured.given(requestSpec).get("/does-not-exist?foo=" + paramValue);

    Awaitility.given().pollInterval(100, TimeUnit.MILLISECONDS)
            .atMost(10, TimeUnit.SECONDS)
            .untilAsserted(new ThrowingRunnable() {
                @Override
                public void run() throws Throwable {
                    try (Stream<Path> files = Files.list(logDirectory)) {
                        Assertions.assertEquals(1, (int) files.count());
                    }
                    Path path = logDirectory.resolve("server.log");
                    Assertions.assertTrue(Files.exists(path));
                    String data = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
                    Assertions.assertTrue(data.contains("404"));
                    Assertions.assertTrue(data.contains("/does-not-exist"));
                    Assertions.assertTrue(data.contains("?foo=" + paramValue),
                            "access log is missing query params");
                    Assertions.assertFalse(data.contains("?foo=" + paramValue + "?foo=" + paramValue),
                            "access log contains duplicated query params");
                    Assertions.assertTrue(data.contains("HTTP/1.0"),
                            "HTTP/1.0 protocol value is missing in the access log");
                }
            });
}
 
源代码14 项目: cosmic   文件: ApiServer.java
public ListenerThread(final ApiServer requestHandler, final int port) {
    try {
        _serverSocket = new ServerSocket(port);
    } catch (final IOException ioex) {
        s_logger.error("error initializing api server", ioex);
        return;
    }

    _params = new BasicHttpParams();
    _params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 30000)
           .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
    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("*", requestHandler);

    // Set up the HTTP service
    _httpService = new HttpService(httpproc, new NoConnectionReuseStrategy(), new DefaultHttpResponseFactory());
    _httpService.setParams(_params);
    _httpService.setHandlerResolver(reqistry);
}
 
源代码15 项目: cosmic   文件: ClusterServiceServletContainer.java
public ListenerThread(final HttpRequestHandler requestHandler, final int port) {
    _executor = Executors.newCachedThreadPool(new NamedThreadFactory("Cluster-Listener"));

    try {
        _serverSocket = new ServerSocket(port);
    } catch (final IOException ioex) {
        s_logger.error("error initializing cluster service servlet container", ioex);
        return;
    }

    _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
    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("/clusterservice", requestHandler);

    // Set up the HTTP service
    _httpService = new HttpService(httpproc, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory());
    _httpService.setParams(_params);
    _httpService.setHandlerResolver(reqistry);
}
 
源代码16 项目: seldon-server   文件: SimpleUrlFetcher.java
@Override
public String getUrl(String url) throws Exception {
    String response_content = "";

    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Mozilla/5.0 (Macintosh;) SeldonBot/1.0");
    httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, httpGetTimeout);
    httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, httpGetTimeout);
    
    try {
        HttpGet httpget = new HttpGet( url );
        httpget.addHeader("Connection", "close");
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            ContentType contentType = ContentType.getOrDefault(entity);
            logger.info("Response contentType: "+contentType);
            
            String contentCharSet = EntityUtils.getContentCharSet(entity);              
            logger.info("Response contentCharSet: "+contentCharSet);
            
            response_content = EntityUtils.toString(entity);
            EntityUtils.consume(entity);
        }
    } catch (Exception e) {
        throw e;
    } finally {
        httpclient.getConnectionManager().closeExpiredConnections();
        httpclient.getConnectionManager().closeIdleConnections(30, TimeUnit.SECONDS);
        httpclient.getConnectionManager().shutdown();
    }
    
    return response_content;
}
 
源代码17 项目: neembuu-uploader   文件: GRupload.java
public void fileUpload() throws Exception {

        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
        HttpPost httppost = new HttpPost(gruploadlink);
        if (gruploadAccount.loginsuccessful) {

            httppost.setHeader("Cookie", GRuploadAccount.getLogincookie() + ";" + GRuploadAccount.getXfsscookie());
        }
        MultipartEntity mpEntity = new MultipartEntity();
        mpEntity.addPart("upload_type", new StringBody("file"));
//        mpEntity.addPart("srv_id", new StringBody(serverID));
        if (gruploadAccount.loginsuccessful) {
            mpEntity.addPart("sess_id", new StringBody(GRuploadAccount.getXfsscookie().substring(5)));
        }
        mpEntity.addPart("srv_tmp_url", new StringBody(tmpserver + "/tmp"));
        mpEntity.addPart("file_0", createMonitoredFileBody());
        httppost.setEntity(mpEntity);
        NULogger.getLogger().info("Now uploading your file into grupload...........................");
        uploading();
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
        NULogger.getLogger().info(response.getStatusLine().toString());
        if (resEntity != null) {

            String tmp = EntityUtils.toString(resEntity);
            NULogger.getLogger().log(Level.INFO, "Upload response : {0}", tmp);

            fnvalue = StringUtils.stringBetweenTwoStrings(tmp, "name='fn'>", "<");
            NULogger.getLogger().log(Level.INFO, "fn value : {0}", fnvalue);

        } else {
            throw new Exception("There might be a problem with your internet connection or server error. Please try again some after time. :(");
        }
    }
 
源代码18 项目: neembuu-uploader   文件: FileSonic.java
public void fileUpload() throws Exception {


        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);

        HttpPost httppost = new HttpPost(postURL);

        httppost.setHeader("Cookie", FileSonicAccount.getLangcookie() + ";" + FileSonicAccount.getSessioncookie() + ";" + FileSonicAccount.getMailcookie() + ";" + FileSonicAccount.getNamecookie() + ";" + FileSonicAccount.getRolecookie() + ";");

        MultipartEntity mpEntity = new MultipartEntity();
        //ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("files[]", createMonitoredFileBody());
        httppost.setEntity(mpEntity);
        uploading();
        NULogger.getLogger().info("Now uploading your file into filesonic...........................");
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
        NULogger.getLogger().info(response.getStatusLine().toString());
        if (resEntity != null) {

            String tmp = EntityUtils.toString(resEntity);
            //NULogger.getLogger().info("response : " + tmp);

        }
        uploadresponse = response.getLastHeader("Location").getValue();
        NULogger.getLogger().log(Level.INFO, "Upload response URL : {0}", uploadresponse);

        uploadresponse = getData(uploadresponse);
        if (uploadresponse.contains("File was successfully uploaded")) {
            NULogger.getLogger().info("File was successfully uploaded :)");

            uploadFinished();
        } else {
            throw new Exception("There might be a problem with your internet connecivity or server error. Please try after some time. :(");
        }

    }
 
源代码19 项目: neembuu-uploader   文件: Oron.java
public void fileUpload() throws Exception {
    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    HttpPost httppost = new HttpPost(oronlink);
    if (oronAccount.loginsuccessful) {

        httppost.setHeader("Cookie", OronAccount.getLogincookie() + ";" + OronAccount.getXfsscookie());
    }
    MultipartEntity mpEntity = new MultipartEntity();
    mpEntity.addPart("upload_type", new StringBody("file"));
    mpEntity.addPart("srv_id", new StringBody(serverID));
    if (oronAccount.loginsuccessful) {
        mpEntity.addPart("sess_id", new StringBody(OronAccount.getXfsscookie().substring(5)));
    }
    mpEntity.addPart("srv_tmp_url", new StringBody(tmpserver));
    mpEntity.addPart("file_0", createMonitoredFileBody());
    httppost.setEntity(mpEntity);
    NULogger.getLogger().info("Now uploading your file into oron...........................");
    uploading();
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity resEntity = response.getEntity();
    NULogger.getLogger().info(response.getStatusLine().toString());
    if (resEntity != null) {

        String tmp = EntityUtils.toString(resEntity);
        NULogger.getLogger().log(Level.INFO, "Upload response : {0}", tmp);

        fnvalue = StringUtils.stringBetweenTwoStrings(tmp, "name='fn' value='", "'");
        NULogger.getLogger().log(Level.INFO, "fn value : {0}", fnvalue);

    } else {
        throw new Exception("There might be a problem with your internet connection or server problem. Please try again after some time. :(");
    }


}
 
public static void fileUpload() throws IOException {
        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
        file = new File("H:\\FileServeUploader.java");


//        if(!username.isEmpty() &&  !password.isEmpty())
//            postURL = megauploadlink + "upload_done.php?UPLOAD_IDENTIFIER=" + uploadID + "&user=undefined&s=" + filelength;
//        else
//           postURL = megauploadlink + "upload_done.php?UPLOAD_IDENTIFIER=" + uploadID + "&"+usercookie+"&s=" + filelength; 
        HttpPost httppost = new HttpPost(postURL);

        httppost.setHeader("Cookie", uprandcookie + ";" + autologincookie);
        MultipartEntity mpEntity = new MultipartEntity();
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("MAX_FILE_SIZE", new StringBody("2097152000"));
        mpEntity.addPart("UPLOAD_IDENTIFIER", new StringBody(uid));
        mpEntity.addPart("go", new StringBody("1"));
        mpEntity.addPart("files", cbFile);
        httppost.setEntity(mpEntity);
        System.out.println("Now uploading your file into depositfiles...........................");
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();

        System.out.println(response.getStatusLine());
        if (resEntity != null) {

            uploadresponse = EntityUtils.toString(resEntity);
            downloadlink = parseResponse(uploadresponse, "ud_download_url = '", "'");
            deletelink = parseResponse(uploadresponse, "ud_delete_url = '", "'");
            System.out.println("download link : " + downloadlink);
            System.out.println("delete link : " + deletelink);

        }
    }
 
源代码21 项目: neembuu-uploader   文件: FileServeUploaderPlugin.java
public static void fileUpload() throws Exception {
        HttpClient client = new DefaultHttpClient();
        client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);

        HttpPost post = new HttpPost(postURL);
        post.setHeader("Cookie", dashboardcookie + ";");

        MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

// For File parameters
        entity.addPart("file", new FileBody(new File("/home/vigneshwaran/Documents/TNEB Online Payment 3.pdf")));

// For usual String parameters
//        entity.addPart(paramName, new StringBody(paramValue.toString(), "text/plain",
//                Charset.forName("UTF-8")));
//
        post.setEntity(entity);

// Here we go!
        String response = EntityUtils.toString(client.execute(post).getEntity(), "UTF-8");
        System.out.println("res : " + response);
        client.getConnectionManager().shutdown();
        uploadresponse = response;
        String shortencode = parseResponse(uploadresponse, "\"shortenCode\":\"", "\"");
        String fileName = parseResponse(uploadresponse, "\"fileName\":\"", "\"");
        String deleteCode = parseResponse(uploadresponse, "\"deleteCode\":\"", "\"");
        downloadlink = "http://www.fileserve.com/file/" + shortencode + "/" + fileName;
        deletelink = "http://www.fileserve.com/file/" + shortencode + "/delete/" + deleteCode;
        System.out.println("Download Link : " + downloadlink);
        System.out.println("Delete Link : " + deletelink);
    }
 
源代码22 项目: neembuu-uploader   文件: FileSonicUploaderPlugin.java
public void fileUpload() throws Exception {
        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
        file = new File("/home/vigneshwaran/VIGNESH/dinesh.txt");
        HttpPost httppost = new HttpPost(postURL);
        httppost.setHeader("Cookie", langcookie + ";" + sessioncookie + ";" + mailcookie + ";" + namecookie + ";" + rolecookie + ";" + msgreadcookie + ";" + msgcheckcookie + ";");
        MultipartEntity mpEntity = new MultipartEntity();
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("files[]", cbFile);
        httppost.setEntity(mpEntity);
        System.out.println("Now uploading your file into filesonic...........................");
        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("response : " + tmp);
//
//        }
        uploadresponse = response.getLastHeader("Location").getValue();
        System.out.println("Upload response URL : " + uploadresponse);
        uploadresponse = getData(uploadresponse);
        if (uploadresponse.contains("File was successfully uploaded")) {
            System.out.println("File was successfully uploaded :)");
        } else {
            throw new Exception("There might be a problem with your internet connecivity or server error. Please try after some time. :(");
        }
    }
 
public static void fileUpload() throws Exception {
        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
        file = new File("C:\\Documents and Settings\\dinesh\\Desktop\\FourSharedUploaderPlugin.java");
//        file = new File("e:\\dinesh.txt");
        HttpPost httppost = new HttpPost("http://upload.1fichier.com/en/upload.cgi?id=" + uid);
        if (login) {
            httppost.setHeader("Cookie", sidcookie);
        }
        MultipartEntity mpEntity = new MultipartEntity();
        ContentBody cbFile = new FileBody(file);
//        mpEntity.addPart("UPLOAD_IDENTIFIER", new StringBody(uploadid));
        mpEntity.addPart("file[]", cbFile);
        mpEntity.addPart("domain", new StringBody("0"));
        httppost.setEntity(mpEntity);
        System.out.println("Now uploading your file into 1fichier...........................");
        System.out.println("Now executing......." + httppost.getRequestLine());
        HttpResponse response = httpclient.execute(httppost);
//        HttpEntity resEntity = response.getEntity();
        System.out.println(response.getStatusLine());
        if (response.containsHeader("Location")) {
            uploadresponse = response.getFirstHeader("Location").getValue();
            System.out.println("Upload location link : " + uploadresponse);
        } else {
            throw new Exception("There might be a problem with your internet connection or server error. Please try again");
        }
    }
 
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/VIGNESH/dinesh.txt");
        HttpPost httppost = new HttpPost(postURL);
        //httppost.setHeader("Cookie", usercookie);
        MultipartEntity mpEntity = new MultipartEntity();
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("sub", new StringBody("upload"));
        mpEntity.addPart("cookie", new StringBody(cookie));
        mpEntity.addPart("folder", new StringBody("0"));
        mpEntity.addPart("filecontent", cbFile);
        httppost.setEntity(mpEntity);
        System.out.println("Now uploading your file into rs...........................");
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();

        System.out.println(response.getStatusLine());
        if (resEntity != null) {

            uploadresponse = EntityUtils.toString(resEntity);
            System.out.println("Actual response : " + uploadresponse);
            uploadresponse = uploadresponse.replace("COMPLETE\n", "");

//            downloadid=uploadresponse.substring(uploadresponse.indexOf("E")+1);
            downloadid = uploadresponse.substring(0, uploadresponse.indexOf(","));
            uploadresponse = uploadresponse.replace(downloadid + ",", "");
            filename = uploadresponse.substring(0, uploadresponse.indexOf(","));
            System.out.println("download id : " + downloadid);
//            filename=uploadresponse.substring(uploadresponse.indexOf(","));
//            filename=uploadresponse.substring(0, uploadresponse.indexOf(","));
            System.out.println("File name : " + filename);
            downloadlink = "http://rapidshare.com/files/" + downloadid + "/" + filename;
            System.out.println("Download Link :" + downloadlink);
        }
    }
 
源代码25 项目: neembuu-uploader   文件: BoxUploaderPlugin.java
public static void fileUpload() throws Exception {
        HttpClient client = new DefaultHttpClient();
        client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);


        //https://upload.box.net/api/1.0/upload/<auth token>/<folder id>
//nid1qr129kzte5gx1x47sypfj4exuo8d
        HttpPost post = new HttpPost("https://upload.box.net/api/1.0/upload/nid1qr129kzte5gx1x47sypfj4exuo8d/0");
//        HttpPost post = new HttpPost("https://upload.box.net/api/1.0/upload/" + auth_token + "/0");
        MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

// For File parameters
        entity.addPart("file", new FileBody(new File("C:\\Documents and Settings\\dinesh\\Desktop\\GrUploaderPlugin.java")));

        entity.addPart("share", new StringBody("1"));
// For usual String parameters
        post.setEntity(entity);

        System.out.println("Executing ......" + post.getRequestLine());

// Here we go!
        System.out.println("Now uploading your files into box.com");
        String response = EntityUtils.toString(client.execute(post).getEntity(), "UTF-8");
        System.out.println("res : " + response);
        client.getConnectionManager().shutdown();
        if (response.contains("upload_ok") && !response.contains("error")) {

            downloadlink = parseResponse(response, "public_name=\"", "\"");
            downloadlink = "http://www.box.com/s/" + downloadlink;
            System.out.println("Download Link : " + downloadlink);
        } else {
            throw new Exception("There might be a problem with your internet connection or server error. Please try again later :(");
        }

    }
 
源代码26 项目: neembuu-uploader   文件: GigaSizeUploaderPlugin.java
public static void fileUpload() throws IOException {
        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
        file = new File("/media/backup/Projects/NU/NeembuuUploader/test/neembuuuploader/test/plugins/RapidShareUploaderPlugin.java");
//        file = new File("e:\\dinesh.txt");
        HttpPost httppost = new HttpPost("http://www.gigasize.com/uploadie");
        httppost.setHeader("Cookie", cookies.toString());
        MultipartEntity mpEntity = new MultipartEntity();
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("UPLOAD_IDENTIFIER", new StringBody(uploadid));
        mpEntity.addPart("sid", new StringBody(sid));
        mpEntity.addPart("fileUpload1", cbFile);
        httppost.setEntity(mpEntity);
        System.out.println("Now uploading your file into Gigasize...........................");
        System.out.println("Now executing......." + httppost.getRequestLine());
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
        System.out.println(response.getStatusLine());
        if (resEntity != null) {
            sid = "";
            sid = EntityUtils.toString(resEntity);
            System.out.println("After upload sid value : " + sid);

        }
        //    uploadresponse = response.getLastHeader("Location").getValue();
        //  System.out.println("Upload response : " + uploadresponse);
    }
 
源代码27 项目: neembuu-uploader   文件: OronUploaderPlugin.java
public static void fileUpload() throws IOException {
        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
        file = new File("H:\\Dinesh.java");
        HttpPost httppost = new HttpPost(oronlink);
        if (login) {

            httppost.setHeader("Cookie", logincookie + ";" + xfsscookie);
        }
        MultipartEntity mpEntity = new MultipartEntity();
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("upload_type", new StringBody("file"));
        mpEntity.addPart("srv_id", new StringBody(serverID));
        if (login) {
            mpEntity.addPart("sess_id", new StringBody(xfsscookie.substring(5)));
        }
        mpEntity.addPart("srv_tmp_url", new StringBody(tmpserver));
        mpEntity.addPart("file_0", cbFile);
        httppost.setEntity(mpEntity);
        System.out.println("Now uploading your file into oron...........................");
        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("Upload response : " + tmp);

            fnvalue = parseResponse(tmp, "name='fn' value='", "'");
            System.out.println("fn value : " + fnvalue);

        }
//        uploadresponse = response.getLastHeader("Location").getValue();
//        System.out.println("Upload response : " + uploadresponse);
    }
 
public static void fileUpload() throws IOException {
    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    file = new File("H:\\c programs.doc");
    filelength = file.length();
    if (!username.isEmpty() && !password.isEmpty()) {
        postURL = megauploadlink + "upload_done.php?UPLOAD_IDENTIFIER=" + uploadID + "&user=undefined&s=" + filelength;
    } else {
        postURL = megauploadlink + "upload_done.php?UPLOAD_IDENTIFIER=" + uploadID + "&" + usercookie + "&s=" + filelength;
    }
    HttpPost httppost = new HttpPost(postURL);
    httppost.setHeader("Cookie", usercookie);
    MultipartEntity mpEntity = new MultipartEntity();
    ContentBody cbFile = new FileBody(file);
    mpEntity.addPart("", cbFile);
    httppost.setEntity(mpEntity);
    System.out.println("Now uploading your file into megaupload...........................");
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity resEntity = response.getEntity();

    System.out.println(response.getStatusLine());
    if (resEntity != null) {

        downloadlink = EntityUtils.toString(resEntity);


    }
}
 
源代码29 项目: neembuu-uploader   文件: GrUploaderPlugin.java
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\\GrUploaderPlugin.java");
        HttpPost httppost = new HttpPost(gruploadlink);
        if (login) {

            httppost.setHeader("Cookie", logincookie + ";" + xfsscookie);
        }
        MultipartEntity mpEntity = new MultipartEntity();
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("upload_type", new StringBody("file"));
//        mpEntity.addPart("srv_id", new StringBody(serverID));
        if (login) {
            mpEntity.addPart("sess_id", new StringBody(xfsscookie.substring(5)));
        }
        mpEntity.addPart("srv_tmp_url", new StringBody(tmpserver + "/tmp"));
        mpEntity.addPart("file_0", cbFile);
        httppost.setEntity(mpEntity);
        System.out.println("Now uploading your file into grupload...........................");
        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("Upload response : " + tmp);

            fnvalue = parseResponse(tmp, "name='fn'>", "<");
            System.out.println("fn value : " + fnvalue);

        }
//        uploadresponse = response.getLastHeader("Location").getValue();
//        System.out.println("Upload response : " + uploadresponse);
    }
 
@Override
public DefaultHttpClient create(final HttpMethod method, final URI uri) {
  final DefaultHttpClient httpClient = super.create(method, uri);

  httpClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
  httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8");

  final int timeout = 1000;
  HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), timeout);
  HttpConnectionParams.setSoTimeout(httpClient.getParams(), timeout);

  return httpClient;
}
 
 类所在包
 类方法
 同包方法