HTTP到达AS会出现500错误

时间:2014-05-03 03:03:52

标签: java http get sap

我正在尝试使用java代码登录SAP CE cerver。我得到HTTP ststus代码500作为回应。我做错了什么?

public class GetExample {
public static void main(String[] args)throws Exception {
    GetExample getExample =  new GetExample();
    URL gatewayServiceUrl = new URL("http://192.168.55.12:56400/nwa");
    HttpURLConnection connection = (HttpURLConnection) gatewayServiceUrl.openConnection();
    connection.setRequestMethod("GET");
    connection.setRequestProperty("Authorization", getExample.getBasicAuth());
    connection.connect();
    if (HttpURLConnection.HTTP_OK == connection.getResponseCode()) {
        System.out.println("success");
        System.out.println(getExample.getDataFromStream(connection.getInputStream()));
    } else {
        System.out.println("success");
        System.out.println(getExample.getDataFromStream(connection.getErrorStream()));
    }
    System.out.println(connection.getResponseCode());

}
private String getBasicAuth() {
    String userpass = "bpm-vikask" + ":" + "Init-12345";
    return "Basic "
    + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass
            .getBytes());
}
private String getDataFromStream(InputStream stream) throws IOException {
    StringBuffer dataBuffer = new StringBuffer();
    BufferedReader inStream = new BufferedReader(new InputStreamReader(
            stream));
    String data = "";
    while ((data = inStream.readLine()) != null) {
        dataBuffer.append(data);
    }
    inStream.close();

    return dataBuffer.toString();
}

}

1 个答案:

答案 0 :(得分:0)

500响应表示“内部错误”,表示服务器端出现问题。我建议你检查服务器端的日志文件。错误流中也可能有线索......您显然已经在阅读。