Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Restful API codeigniter-JAVA问题_Java_Api_Codeigniter - Fatal编程技术网

Restful API codeigniter-JAVA问题

Restful API codeigniter-JAVA问题,java,api,codeigniter,Java,Api,Codeigniter,我们使用API构建了我们的API,该API为生产准备,并作为我们移动应用程序实现的一部分使用 我们在Java中使用API时遇到了一个问题 httpConnection = (HttpConnection) Connector.open(url, Connector.READ, true); // Set content type by given parameter...... httpConnection.setRequestProperty("Accept", contentType); h

我们使用API构建了我们的API,该API为生产准备,并作为我们移动应用程序实现的一部分使用

我们在Java中使用API时遇到了一个问题

httpConnection = (HttpConnection) Connector.open(url, Connector.READ, true);
// Set content type by given parameter......
httpConnection.setRequestProperty("Accept", contentType);
httpConnection.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/FCLDC-1.0");
httpConnection.setRequestProperty("Content-Type", contentType);
httpConnection.setRequestProperty("TK-API-KEY", UrlFactory.TK_API_KEY);

// httpConnection.setRequestProperty("Model",
// StyleUtil.getDeviceModel());
if (httpConnection.getResponseCode() == 302)
{
  String redirectUrl =  httpConnection.getHeaderField("Location");
  httpConnection = (HttpConnection) Connector.open(redirectUrl, Connector.READ_WRITE, true);
}

if (httpConnection.getResponseCode() == HttpConnection.HTTP_OK)
{
  io = httpConnection.openInputStream();

  int ch;
  while ((ch = io.read()) != -1)
  {
    bo.write(ch);
  }

}

httpConnection.getResponseCode()
无法获取状态代码并返回格式错误的异常。我们的API服务器是NGINX。

如果头字段设置不正确,将引发畸形异常。请使用不同的标题以及不同的用户代理进行检查。尝试使用
httpConnection.setDoOutput(true)

您可以发布它返回的内容吗?如果没有必要,您可以给一个机会。只需先从控制台java应用程序中尝试URL,然后从那里继续。尝试使用类似Advanced REST client()的客户端来查看服务器返回的内容。如果您可以发布响应头,那么可以尝试使用poster或SOAP UI来测试您的REST请求/响应。甚至可以从命令中使用CURL,就像在*NIX机器上一样。这样做将验证您请求的信息是否可用,并且您可以从中排除更多故障。