1

org.apache.http.ProtocolException: Not a valid protocol version: <html>に従って XML をサーバーにポストしようとすると、エラー " " が表示されます

        HttpParams params = new SyncBasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "UTF-8");
    HttpProtocolParams.setUserAgent(params, "Apache-HttpClient/4.0.1 (java 1.5)");
    HttpProtocolParams.setUseExpectContinue(params, true);

    HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
            // Required protocol interceptors
            new RequestContent(),
            new RequestTargetHost(),
            // Recommended protocol interceptors
            new RequestConnControl(),
            new RequestUserAgent(),
            new RequestExpectContinue()});

    HttpRequestExecutor httpexecutor = new HttpRequestExecutor();

    HttpContext context = new BasicHttpContext(null);

    // Host to post
    HttpHost host = new HttpHost(hostUrl, hostPort);

    DefaultHttpClientConnection conn = new DefaultHttpClientConnection();

    context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
    context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, host);


        try {
            SocketAddress sockaddr = new InetSocketAddress(host.getHostName(), host.getPort());
            Socket socket = new Socket();
            socket.connect(sockaddr);
            conn.bind(socket, params);
            BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST","");

            HttpEntity requestBody = new StringEntity(xmlToPost, "UTF-8");
            request.setEntity(requestBody);


          request.setParams(params);
          httpexecutor.preProcess(request, httpproc, context);

          // FAILS HERE WITH THE MESSAGE "org.apache.http.ProtocolException: Not a valid protocol version: <html>"
          HttpResponse response = httpexecutor.execute(request, conn, context);
          response.setParams(params);
          httpexecutor.postProcess(response, httpproc, context);


    } catch (Exception e) {            

    }

Firefoxで「Poster」プラグインを使用すると正しく機能するため、サーバーではないことは確かです。xml を投稿しようとしていますが、それをこのコードに追加するかどうか、または追加する方法がわかりません。

4

0 に答える 0