getInputStream 抛出异常

发布于 2024-10-30 00:41:09 字数 1873 浏览 4 评论 0原文

我正在尝试调用 Web 服务并解析返回的 XML,因此我的调用 URL 是:

http://192.168.1.12/cr.ws/CarCategories.asmx/CarCategoryComparatorRQ?IdUser=1076&IdCurrency=1&IdLanguage=1&IdCarCategory=0&IdPickupRentCarAgencies=3&IdReturnRentCarAgencies=3&PickupDate=6/4/2011&ReturnDate=9/4/2011&Supplier=Prima%20Rent%20a%20Car&b=prima

在浏览器中我得到了所需的响应:

<CarCategoryComparatorRS>
<CarCategory>
<IdCar>22</IdCar>
<IdCarCategory>22</IdCarCategory>
<Supplier>AvantGarde Rent a Car</Supplier>
<PickupRentCarAgencies>Tunis;  Aéroport de Tunis-Carthage</PickupRentCarAgencies>
<IdPickupRentCarAgencies>5</IdPickupRentCarAgencies>
<ReturnRentCarAgencies>Tunis;  Aéroport de Tunis-Carthage</ReturnRentCarAgencies>
<IdReturnRentCarAgencies>5</IdReturnRentCarAgencies>
<IdUser>705</IdUser>
<Title>Catégorie A [ex:Kia Rio;Renault Symbol]</Title>
<IdCurrency>1</IdCurrency>
<ImageUrl>Car-22-20090521-125545.jpg</ImageUrl>
<MemberReductionValue>0</MemberReductionValue>
<Rate>150</Rate>
<DelayRate>0</DelayRate>
<ReductionValue>135</ReductionValue>
<DayRate>45</DayRate>
<Reduction>10%</Reduction>
<AccompteValue>67.500</AccompteValue>
<Accompte>50</Accompte>
<TotalRate>0000135000</TotalRate>
</CarCategory>
</CarCategoryComparatorRS>

但是这个函数引发了 java.io.FileNotFoundException

protected InputStream getInputStream() {
        try {
            return feedUrl.openConnection().getInputStream();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

请帮助我,我浪费了几个小时的搜索时间,但什么也没得到: (

谢谢。

I'm trying to invoke a webservice and parse the returned XML, so my invoke URL is :

http://192.168.1.12/cr.ws/CarCategories.asmx/CarCategoryComparatorRQ?IdUser=1076&IdCurrency=1&IdLanguage=1&IdCarCategory=0&IdPickupRentCarAgencies=3&IdReturnRentCarAgencies=3&PickupDate=6/4/2011&ReturnDate=9/4/2011&Supplier=Prima%20Rent%20a%20Car&b=prima

in my browser I get the desired response :

<CarCategoryComparatorRS>
<CarCategory>
<IdCar>22</IdCar>
<IdCarCategory>22</IdCarCategory>
<Supplier>AvantGarde Rent a Car</Supplier>
<PickupRentCarAgencies>Tunis;  Aéroport de Tunis-Carthage</PickupRentCarAgencies>
<IdPickupRentCarAgencies>5</IdPickupRentCarAgencies>
<ReturnRentCarAgencies>Tunis;  Aéroport de Tunis-Carthage</ReturnRentCarAgencies>
<IdReturnRentCarAgencies>5</IdReturnRentCarAgencies>
<IdUser>705</IdUser>
<Title>Catégorie A [ex:Kia Rio;Renault Symbol]</Title>
<IdCurrency>1</IdCurrency>
<ImageUrl>Car-22-20090521-125545.jpg</ImageUrl>
<MemberReductionValue>0</MemberReductionValue>
<Rate>150</Rate>
<DelayRate>0</DelayRate>
<ReductionValue>135</ReductionValue>
<DayRate>45</DayRate>
<Reduction>10%</Reduction>
<AccompteValue>67.500</AccompteValue>
<Accompte>50</Accompte>
<TotalRate>0000135000</TotalRate>
</CarCategory>
</CarCategoryComparatorRS>

But this function trows java.io.FileNotFoundException

protected InputStream getInputStream() {
        try {
            return feedUrl.openConnection().getInputStream();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

Please help me, I wasted couple hours searching but nothing :(

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

凉城凉梦凉人心 2024-11-06 00:41:09

该错误是由此参数中的空格引起的:“Supplier=Prima Rent a Car”,因此我将此参数替换为 UrlEncoder.encode("Supplier=Prima Rent a Car") 并且它有效。

The error is caused by the spaces in this param :"Supplier=Prima Rent a Car", so i replaced this param by UrlEncoder.encode("Supplier=Prima Rent a Car") and it worked.

我的痛♀有谁懂 2024-11-06 00:41:09

如果您在设备的浏览器地址栏中输入该 URL,您会得到什么吗?

If you type that URL in your device's browser address bar do you get anything?

套路撩心 2024-11-06 00:41:09

您似乎正在尝试请求本地计算机或 LAN 上的地址。您是否在 Android 设备上请求此操作?我的猜测是您需要在计算机上的不同接口上运行服务器或打开与所需端口的连接。

It looks like you are trying to request an address on a local machine or LAN. Are you requesting this on the android device? My guess is you need to run your server on the machine on a different interface or open up connections to the required port.

安稳善良 2024-11-06 00:41:09

我认为您的网址被解释为文件网址。

在调用 openConnection 之前记录您的 url 作为健全性检查怎么样:

Log.e("MyApp", feedUrl);

再想一想,您可以发布 logcat 输出吗?我对您的代码如何抛出 FileNotFoundException 表示怀疑。

I think your url is being interpreted as a file url.

What about logging your url before you call openConnection as a sanity check:

Log.e("MyApp", feedUrl);

On second thought, could you post the logcat output? I'm skeptical as to how your code could ever throw a FileNotFoundException.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文