SAAJ发送邮件请求

时间:2017-09-21 15:51:59

标签: java http httprequest

我有一个脚本,使用curl命令通过HTTP发送x文件(测试文件在脚本目录中):

curl -v -H 'SENDER_CODE: AAAA' -H 'SENDER_DN: TEST' -H 'SSL_CLIENT_VERIFY: SUCCESS' -d "filename=test&tipofile=10" --data-urlencode "filexml@test.xml" http://localhost:8080/receiver

它正常工作。

现在我正在使用Java语言开发相同的程序。这是我的代码:

                URL obj = new URL("http://localhost:8080/receiver");
                HttpURLConnection connHttp = (HttpURLConnection) obj.openConnection();

                //connHttp.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                connHttp.setRequestProperty ( "Content-Type", "text/xml" );
                connHttp.setRequestProperty("accept-charset", "UTF-8");

                connHttp.setRequestProperty("SENDER_CODE", "AAAA");
                connHttp.setRequestProperty("SENDER_DN", "TEST");
                connHttp.setRequestProperty("SSL_CLIENT_VERIFY", "SUCCESS");

                //connHttp.setRequestProperty("Accept-Charset", "ISO-8859-1,utf-8");
                connHttp.setRequestMethod("POST");

                String urlParameters = "filename=test&tipofile=12";

                String s = "<?xml ..... xml>";

                // Send post request
                connHttp.setDoOutput(true);
                OutputStream wr = new BufferedOutputStream(connHttp.getOutputStream());
                wr.write(urlParameters.getBytes());
                wr.write(s.getBytes());
                wr.flush();
                wr.close();

Web服务返回406 http错误代码。我找不到错误。

请问你能帮帮我吗?

由于 弗朗西斯科

0 个答案:

没有答案