1

我正在尝试调用 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);
        }

请帮帮我,我浪费了几个小时搜索但什么也没有:(

谢谢。

4

4 回答 4

3

错误是由这个参数中的空格引起的:“Supplier=Prima Rent a Car”,所以我用这个参数替换了UrlEncoder.encode("Supplier=Prima Rent a Car")它,它起作用了。

于 2011-04-04T07:46:29.200 回答
0

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

于 2011-04-03T23:10:29.537 回答
0

看起来您正试图在本地计算机或 LAN 上请求地址。你是在安卓设备上请求这个吗?我的猜测是你需要在机器上的不同接口上运行你的服务器,或者打开到所需端口的连接。

于 2011-04-03T23:56:45.113 回答
0

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

在您调用之前记录您的网址如何openConnection进行完整性检查:

Log.e("MyApp", feedUrl);

再想一想,你能发布 logcat 输出吗?我对您的代码如何抛出FileNotFoundException.

于 2011-04-04T02:03:43.290 回答