2014-02-19 42 views
0

欢迎大家! 我在这里是新来的,我正在寻找Prestashop webservice和Android的解决方案。 我必须编写一个android应用程序,它解析来自prestashop web服务的XML,我不知道该怎么做。 Offcourse,我在prestashop中设置了web服务,它生成一个xml。最后,我有一个xml:从Prestashop webservice解析Android中的XML

<prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> 
    <api shop_name="myShop"> 
    <addresses xlink:href="https://myshop.pl/api/addresses" get="true" put="false" post="true" delete="false" head="true"> 
     <description xlink:href="https://myshop.pl/api/addresses" get="true" put="false" post="true" delete="false" head="true">The Customer, Manufacturer and Customer addresses</description> 
     <schema xlink:href="https://myshop.pl/api/addresses?schema=blank" type="blank"/> 
     <schema xlink:href="https://myshop.pl/api/addresses?schema=synopsis" type="synopsis"/> 
    </addresses> 
    </api> 
</prestashop> 

我尝试使用此tutorial来解析上面的XML,但问题是java.io.FileNotFoundException在为InputStream stream = conn.getInputStream()行。

难道有谁能帮助我?

对不起,我的英文,如果有任何错误的文字。

+0

检查康恩它首先是否为空或不是? – Naren

+0

您是否可以从外部访问您的服务url(例如,在浏览器中) – bachr

回答

0

我解决了这个问题,通过增加前connect()方法这一行:

String userpassword = "key_authentication"+":"+""; // empty password should not be missed 
String encoded = new String(Base64.encode(userpassword.getBytes(), Base64.DEFAULT)); 
connection.setRequestProperty("Authorization", "Basic " + encoded); 
+0

如果您只传递'username'参数并错过传递PrestaShop API的空密码,它将返回401 http错误代码,这意味着未经授权。你可以看看http://stackoverflow.com/questions/22404778/prestashop-and-web-servicerestful-httpurlconnection-bufferedreader – VSB