HTTP / 1.1 404未找到Http post请求失败

时间:2015-08-09 08:50:11

标签: java scala http-post

我正在尝试使用this rest api在apache ranger中使用scala / java代码创建一个hdfs存储库。在这里我们需要以json形式传递参数。这是我的代码

def createReposity() {
    val httpclient = new DefaultHttpClient()
    val httpPost = new HttpPost("http://localhost:6080/service/public/api/repository")
    httpPost.setHeader("content-type", "application/json")
    httpPost.setHeader("Accept", "application/json")
    httpPost.addHeader(BasicScheme.authenticate(
      new UsernamePasswordCredentials(username, password),
      "UTF-8", false))
    val reqEntity = new StringEntity(getJson)
    httpPost.setEntity(reqEntity)
    val response = httpclient.execute(httpPost)
    println(response.getStatusLine().getStatusCode())
  }

def getJson(): String = {
    var json = "{\"name\": \"hadoopd_hdfs\",\"description\": \"hdfs repository using curl\","
    json += "\"repositoryType\": \"hdfs\",\"config\": \"{"
    json += "\"username\": \"admin\","
    json += "\"password\": \"admin\","
    json += "\"fs.default.name\": \"hdfs://localhost:9000\","
    json += "\"hadoop.security.authorization\": \"true\","
    json += "\"hadoop.security.authentication\": \"simple\","
    json += "\"hadoop.security.auth_to_local\": \"\","
    json += "\"dfs.datanode.kerberos.principal\": \"\","
    json += "\"dfs.namenode.kerberos.principal\": \"\","
    json += "\"dfs.secondary.namenode.kerberos.principal\": \"\","
    json += "\"commonNameForCertificate\": \"\"}\","
    json += "\"isActive\": true}"
    json
  }

当我执行此代码时,它会找不到错误代码404。请指导我出了什么问题?

感谢

0 个答案:

没有答案