JAVA Apache HTTPClient无法处理Curl可以处理的链接,响应为403

时间:2018-06-21 10:11:45

标签: java apache curl httpclient

我想使用ApacheHTTPClient下载此链接“ https://www.comune.ciampino.roma.it/”,Curl响应为200,确定,Apache响应为403,禁止。如果是ssl证书问题或身份验证问题(该站点不需要身份验证),我就不会。 有效的curl命令是:

import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import AppBar from '@material-ui/core/AppBar';
import Tabs from '@material-ui/core/Tabs';
import Tab from '@material-ui/core/Tab';
import Typography from '@material-ui/core/Typography';

function TabContainer(props) {
  return (
    <Typography component="div" style={{ padding: 8 * 3 }}>
      {props.children}
    </Typography>
  );
}

TabContainer.propTypes = {
  children: PropTypes.node.isRequired,
};

const styles = theme => ({
  root: {
    flexGrow: 1,
    backgroundColor: theme.palette.background.paper,
  },
  tabRoot: {
    backgroundColor: theme.palette.background.paper,
    flexGrow: 1,
    color: 'black',
    fontWeight: 'bold'
  }
});

class SimpleTabs extends React.Component {
  state = {
    value: 0,
  };

  handleChange = (event, value) => {
    this.setState({ value });
  };

  render() {
    const { classes } = this.props;
    const { value } = this.state;

    return (
      <div className={classes.root}>
        <AppBar position="static">
          <Tabs className={classes.tabRoot} value={value} onChange={this.handleChange}>
            <Tab label="Item One" />
            <Tab label="Item Two" />
          </Tabs>
        </AppBar>
        {value === 0 && <TabContainer>Item One</TabContainer>}
        {value === 1 && <TabContainer>Item Two</TabContainer>}
        {value === 2 && <TabContainer>Item Three</TabContainer>}
      </div>
    );
  }
}

SimpleTabs.propTypes = {
  classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(SimpleTabs);

requestConfig是:

curl -v -i https://www.comune.ciampino.roma.it/
*   Trying 62.149.140.217...
* TCP_NODELAY set
* Connected to www.comune.ciampino.roma.it (62.149.140.217) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: OU=Domain Control Validated by Actalis S.p.A.; CN=    
*.comune.ciampino.roma.it
*  start date: Mar 22 01:56:23 2018 GMT
*  expire date: Apr 20 09:17:23 2019 GMT
*  subjectAltName: host "www.comune.ciampino.roma.it" matched cert's "    
*.comune.ciampino.roma.it"
*  issuer: C=IT; ST=Bergamo; L=Ponte San Pietro; O=Actalis 
S.p.A./03358520967; CN=Actalis Domain Validation Server CA G1
*  SSL certificate verify ok.
> GET / HTTP/1.1
> Host: www.comune.ciampino.roma.it
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Date: Thu, 21 Jun 2018 09:36:37 GMT
Date: Thu, 21 Jun 2018 09:36:37 GMT
< Server: Apache
Server: Apache
< P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
< Cache-Control: no-cache
Cache-Control: no-cache
< Pragma: no-cache
Pragma: no-cache
< Set-Cookie: 
df5dc131b556c800c7d350a7d5a633f1=0fpj928ov79ssg7egumkr6j8u1; path=/; 
secure
Set-Cookie: 
df5dc131b556c800c7d350a7d5a633f1=0fpj928ov79ssg7egumkr6j8u1; path=/; 
secure
< Transfer-Encoding: chunked
Transfer-Encoding: chunked
< Content-Type: text/html; charset=utf-8
Content-Type: text/html; charset=utf-8

让我知道您是否还需要httpclient配置。谢谢。

0 个答案:

没有答案