使用http连接找不到文件异常

时间:2012-03-21 04:14:16

标签: android

我必须发布xml输入http://180.151.60.73/Sales/service.asmx/UpdateOpportunity?xml=,它将异常显示为

 03-21 09:51:07.483: WARN/System.err(2531): java.io.FileNotFoundException: http://180.151.60.73/Sales/service.asmx/UpdateOpportunity?xml=
    03-21 09:51:07.493: WARN/System.err(2531):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:1162)
    03-21 09:51:07.493: WARN/System.err(2531):     at com.jems.common.ParentActivity.getXmlData(ParentActivity.java:218)
    03-21 09:51:07.493: WARN/System.err(2531):     at com.jems.salesforce.SalesEditActivity.onClick(SalesEditActivity.java:2989)
    03-21 09:51:07.493: WARN/System.err(2531):     at android.view.View.performClick(View.java:2408)
    03-21 09:51:07.493: WARN/System.err(2531):     at android.view.View$PerformClick.run(View.java:8816)
    03-21 09:51:07.493: WARN/System.err(2531):     at android.os.Handler.handleCallback(Handler.java:587)
    03-21 09:51:07.493: WARN/System.err(2531):     at android.os.Handler.dispatchMessage(Handler.java:92)
    03-21 09:51:07.493: WARN/System.err(2531):     at android.os.Looper.loop(Looper.java:123)
    03-21 09:51:07.493: WARN/System.err(2531):     at android.app.ActivityThread.main(ActivityThread.java:4627)
    03-21 09:51:07.503: WARN/System.err(2531):     at java.lang.reflect.Method.invokeNative(Native Method)
    03-21 09:51:07.503: WARN/System.err(2531):     at java.lang.reflect.Method.invoke(Method.java:521)
    03-21 09:51:07.503: WARN/System.err(2531):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    03-21 09:51:07.503: WARN/System.err(2531):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    03-21 09:51:07.503: WARN/System.err(2531):     at dalvik.system.NativeStart.main(Native Method)

我已将此代码用于http连接

byte[] xm=(xmlUrl).getBytes();
                    StringBuffer b1=new StringBuffer();
                    b1.append(xmlUrl);
                       Log.i("xmlurl",""+ xm);
                       SalesActivity sa =new SalesActivity();
                URL url = new URL("http://180.151.60.73/Sales/service.asmx/UpdateOpportunity?xml=");
                HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
                httpURLConnection.setRequestMethod("POST");
                httpURLConnection.setRequestProperty("Connection", "keep-alive");
                httpURLConnection.setRequestProperty("Content-Type", "text/xml");
                httpURLConnection.setRequestProperty("SendChunked", "True");
                httpURLConnection.setDoOutput(true);
                httpURLConnection.setDoInput(true);

                httpURLConnection.connect();

                OutputStream out = httpURLConnection.getOutputStream();
                out.write(xm);    // send request
                InputStream response = httpURLConnection.getInputStream();
                doc = db.parse(response);
                //receive response
                httpURLConnection.disconnect();

xmlurl作为输入也是这个长度太长了......

1 个答案:

答案 0 :(得分:1)

使用

connection.getErrorStream();

而不是

connection.getInputStream();